如何从c#(MVC)中的post url获取NameValuePair数据
我通过添加NameValuePair从android设备发送HttpPost请求,但不知道如何在Controller中获取NameValuePair值 以下是发送请求的代码:-如何从c#(MVC)中的post url获取NameValuePair数据,c#,android,asp.net-mvc,C#,Android,Asp.net Mvc,我通过添加NameValuePair从android设备发送HttpPost请求,但不知道如何在Controller中获取NameValuePair值 以下是发送请求的代码:- HttpPost request=new HttpPost(PostUrl); HttpResponse response; List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(7); nameValuePairs
HttpPost request=new HttpPost(PostUrl);
HttpResponse response;
List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(7);
nameValuePairs.add(new BasicNameValuePair("userName",userName));
nameValuePairs.add(new BasicNameValuePair("password",Password));
nameValuePairs.add(new BasicNameValuePair("deviceId",deviceId));
nameValuePairs.add(new BasicNameValuePair("subdomain",Subdomain));
nameValuePairs.add(new BasicNameValuePair("deviceType",DeviceType));
nameValuePairs.add(new BasicNameValuePair("uniqueId",UniqueId));
nameValuePairs.add(new BasicNameValuePair("appVersion",AppVersion));
request.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
response = client.execute(request);
请告诉我如何在此方法中获取NameValuePair。如果我通过附加到Post Url发送所有参数,则其工作正常,但如果我通过NameValuePair发送,则用户的值始终为null尝试以下操作:
public LoginResponse login(NameValueCollection post)
{
string test1 = post.Get("userName");
string test2 = post.Get("password");
}
此外,如果这是MVC,请选择一个标准结果(在本例中,ContentResult返回一个字符串):
让我知道它是否有效。如果没有,我还有一些其他建议。您能否进一步了解post对象在运行时的值?它也是空的还是有效的NameValuePair列表?请使用浏览器开发工具检查网络通信。在请求中验证名称和值是否正确过帐。另外,您的操作方法上确实有[HttpPost]属性,对吗?我使用这个,这个对我有用。HttpContext当前=HttpContext.current;字符串user_Name=current.Request.Params[“userName”];
public LoginResponse login(NameValueCollection post)
{
string test1 = post.Get("userName");
string test2 = post.Get("password");
}
public ContentResult login(NameValueCollection post)
{
LoginResponse loginResponse = //some method call...
return Content("login", loginResponse)
}