当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Restsharp returns error 404 but link is working in a web browser

问题描述:

I'm trying to send some data to web api but I get error 404: Not found. I tried link in a web browser and it's working fine. I'm using restsharp to post request. Here's my code:

 var restClient = new RestClient(baseUrl);

var request = new RestRequest(resource);

request.Method = Method.POST;

restClient.CookieContainer = new System.Net.CookieContainer();

restClient.UserAgent = "Windows Phone";

restClient.FollowRedirects = false;

request.AddHeader("Content-Type", "application/json; charset=utf-8");

request.RequestFormat = DataFormat.Json;

request.AddBody(new ScoreInputModel{ username = uname, email = mail, password = pass, gender = "Male" });

try

{

restClient.ExecuteAsync(request, (response) =>

{

try

{

MessageBox.Show(response.Content.ToString());

}

catch

{

MessageBox.Show("error");

}

});

}

catch

{

MessageBox.Show("error");

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: