【发布时间】:2016-06-05 16:02:49
【问题描述】:
我正在尝试使用 webClient 将表单发布到服务器。这是我的请求代码。
WebClient myWebClient = new WebClient();
NameValueCollection myNameValueCollection = new NameValueCollection();
myNameValueCollection.Add("about", about);
myNameValueCollection.Add("firstname", firstname);
myNameValueCollection.Add("lastname", lastname);
Uri uri = new Uri("http://192.168.1.102:1992/api/member/updateprofile");
myWebClient.UploadValuesAsync(uri,"POST", myNameValueCollection);
此请求无法到达服务器。我已经检查了 Url,它是正确的,因为我可以使用 fiddler 并使用 httpWebRequest 客户端发出请求。我看不出我的代码有什么问题。这可能是什么问题?
我的服务器端代码如下:
[HttpPost]
[Route("updateprofile")]
public HttpResponseMessage updateProfile()
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
var httpRequest = HttpContext.Current.Request;
return result;
}
【问题讨论】:
-
好的,您正在显示动作的属性路由。但没有与您显示的 url 匹配的控制器路由/路由前缀的详细信息。确认路由并正确配置它们。
标签: c# asp.net-web-api webclient