Domanda

I try to send POST request with parameters with this code:

 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);

But ASP.NET MVC server do not receive this parameters in action method.

È stato utile?

Soluzione

Adapt to this snippet: 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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top