1

我尝试使用以下代码发送带有参数的 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 服务器在 action 方法中没有接收到这个参数。

4

1 回答 1

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);
于 2013-09-12T06:55:26.387 回答