我尝试使用以下代码发送带有参数的POST请求:
var uri = new Uri("http://127.0.0.1:81/login/login");
var client = new DefaultHttpClient();
var par = new BasicHttpParams();
par.SetParameter("username", "admin")
par.SetParameter("password", "****");
var request = new HttpPost(uri);
request.SetParams(par);
var response = client.Execute(request);
但是ASP.NET MVC服务器在动作方法中没有收到这个参数。
答案 0 :(得分:2)
适应此代码段:http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
var httpclient = new DefaultHttpClient();
var nameValuePairs = new ArrayList<INameValuePair>(2);
nameValuePairs.Add(new BasicNameValuePair("username", "admin"));
nameValuePairs.Add(new BasicNameValuePair("password", "***"));
var ent = new UrlEncodedFormEntity(nameValuePairs);
httppost.SetEntity(ent);
var response = httpclient.Execute(httppost);