Thein
Thein

Reputation: 3968

Post request didn't pass parameter android to asp.net in IIS server

I am trying to trigger a create action in my ASP.NET web application from android.

The code seems to be working fine with no errors. I am using IIS 6 in Windows 7. I suspect a missing configuration in IIS?

I didn't get value in the web app.

Android Code:

List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("supplier_name", 
                                          "Thein Htike Aung"));

HttpClient client1 = new DefaultHttpClient();
HttpPost request = 
    new HttpPost("http://192.168.1.104/LogicUniversity/SupplierHandler.ashx");

try {
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
    request.setEntity(formEntity);

    request.addHeader("Content-type", "application/x-www-form-urlencoded");
    HttpResponse response = client1.execute(request);

    BufferedReader in = new BufferedReader(
                          new InputStreamReader(
                                response.getEntity().getContent()));

    String line;
    String page="";
    line = in.readLine();

    while(line!=null)
    {
      page=page+line;
      line=in.readLine();
    }

    Log.i("Page",page);
    in.close();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}             

In Web Handler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using ApplicationLayer.Controllers;
using ApplicationLayer;

namespace PresentationLayer
{
    /// <summary>
    /// Summary description for SupplierHandler
    /// </summary>
    public class SupplierHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string name = context.Request.QueryString["supplier_name"];

            if (name != null)
            {
                Supplier s = new Supplier();
                s.supplier_name = name;
                s.code = "TEST";
                new SupplierController().actionCreateSupplier(s);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

Upvotes: 0

Views: 904

Answers (2)

Kev
Kev

Reputation: 119816

You say that you're using a HTTP POST to push your value(s) to the server yet in your HTTP Handler you're reading from the query string:

string name = context.Request.QueryString["supplier_name"];

This should be:

string name = context.Request.Form["supplier_name"];

Upvotes: 1

clamchoda
clamchoda

Reputation: 4951

192.168.1.104 is specific to your local network. Your HTTPPost request, from the Andriod code, assumes that the Andriod device is on the same local network, is this your intention? This could be one of many causes on why your code work in development, and not production environment. You would need a Static IP configured on your web server to access the web service outside the local network.

Upvotes: 0

Related Questions