我正在尝试向web api发送一些数据,但是我收到错误404:找不到。我尝试在网络浏览器中链接,它工作正常。我使用restsharp发布请求。这是我的代码:
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");
}
}