Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:29:22+00:00 2026-05-19T22:29:22+00:00

I am sending data from android to a Generic handler .ashx page in asp.net

  • 0

I am sending data from android to a Generic handler .ashx page in asp.net using http post. But the handler is not able to recieve data. The thing works with httpGet but not with httppost

The android code

package com.postApp;
/*
 * HTTP POST and BasicNameValuePair
 * */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class postAct extends Activity {
    /** Called when the activity is first created. */

    class login{
        public
        String uname;
        public String pass;

    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


            login l=new login();


        HttpClient client1 = new DefaultHttpClient();
        HttpPost request = new HttpPost("http://10.0.2.2:18089/POC_login/Handler.ashx");      


       l.uname="piyush";
       l.pass="gupta";
              List<NameValuePair> postParameters = new ArrayList<NameValuePair>(3);
            postParameters.add(new BasicNameValuePair("uname", l.uname));
            postParameters.add(new BasicNameValuePair("pass", l.pass));
       try {
            request.setEntity(new UrlEncodedFormEntity(postParameters));
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
            request.setEntity(formEntity);

          HttpResponse response;
          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();
         }
         TextView tv = (TextView) findViewById(R.id.textview);
         tv.setText(page);
         in.close();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }                    
    }


}   

The ashx code

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Linq;

public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) 
    {
        context.Request.ContentType = "text/plain";
       // context.Request.ContentType = "text/html";


        string username=context.Request.QueryString["uname"];
        string password = context.Request.QueryString["pass"];
        context.Response.Write("Hello Piyush");

        NorthwindDataContext db = new NorthwindDataContext();
        var found = (from p in db.Catergories
                    where p.cat_ID == 1
                    select p.cat_name).SingleOrDefault();

    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

Please Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:29:23+00:00Added an answer on May 19, 2026 at 10:29 pm

    The problem is likely due to incorrect handling of the content-type.

    On the Android side, you should set the Content-type header, e.g.:

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

    And then you should not override the content-type on your server, i.e. remove the following from ProcessRequest:

    context.Request.ContentType = "text/plain";
    // context.Request.ContentType = "text/html";
    

    If you still have problems, be sure to check and make sure your server is configured to receive POSTs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sending files from an android app to a asp.net webform using multipart/form-data as
I'm sending data from one page to the next in an MVC2 app. Page
I got problem with sending data in Android using httpPost. I found some example,
I am using URLConnection Object to send data from my android client to server.
Possible Duplicate: Sending and Parsing JSON in Android I am fetching JSON Data from
I'm sending sensor data from an android device to a TCP server in C#.
I am trying sending data from android application (with emulator) to web server (a
I'm trying to make motion controller using the values from android sensors. Currently sending/receiving
How would one go about sending data back to server, from an android application?
I'm sending data from an Android app to a php script which recieves the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.