1

How can i send my android application data (mobileNumber and message) which is in JSON format to server using HTTPS Post request. please help me.

qrtt1
  • 7,746
  • 8
  • 42
  • 62
Santhosh
  • 4,956
  • 12
  • 62
  • 90

1 Answers1

1
HttpClient httpclient =new DefaultHttpClient();

HttpPost  httppost=new HttpPost(name of the website);
try{

    JSONObject j = new JSONObject();
    j.put("engineer", "me");

    httppost.setEntity(new UrlEncodedFormEntity(j));    
    HttpResponse response = httpclient.execute(httppost);

    /*Checking response*/
    if(response!=null)
    {   
        responseBody = EntityUtils.toString(response.getEntity());

    }
    if(responseBody.equals("ok"))
    {

        //...do something

    }
} catch(ClientProtocolException e) {

} catch (IOException e) {
    // TODO Auto-generated catch block
} catch(Exception e){
    e.printStackTrace();
}

You can also can take a look in here: Android JSON HttpClient to send data to PHP server with HttpResponse

Community
  • 1
  • 1
adrian
  • 4,574
  • 17
  • 68
  • 119
  • Thank you. but, it works based on HTTP?? or HTTPS?? Could you please tell me. – Santhosh Aug 02 '11 at 14:47
  • It works on Http for me, haven't tries with https.But is something very simple:).If it helps you don't forget to accept my answer by checking it from the left side.Thanks:) – adrian Aug 02 '11 at 14:49
  • How can i change the above code to work on HTTPS?? Could you please tell me. – Santhosh Aug 02 '11 at 14:59
  • sorry for the late reply but it seems that this works for both http and https!Did you try it and it is not working? – adrian Aug 02 '11 at 16:48
  • I haven't tried. But i want to know whether it works for "Https" also or not? can you please clarify me. – Santhosh Aug 03 '11 at 06:17
  • It wirks for both....just try it.It will take you 5 minutes.Not such a big deal....:) – adrian Aug 03 '11 at 06:33
  • @adrian...i am doing like this: http://stackoverflow.com/questions/18720923/sending-json-params-with-https-request......... can you please tell me where i am wrong because its not working well. – Noman Sep 10 '13 at 14:01
  • If u are using https and you server requires a certificate for authentication, you need to provide one:) – adrian Sep 11 '13 at 09:17