Search code examples
dot42

dot42 - http POST request with parameters


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.


Solution

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