简体   繁体   中英

Send request and get response from php server for android

I'm trying to send a http request to php server in format of query string (eg: url?values) to server and get the response on my android device. But HttpPost httppost = new HttpPost(URL); is throwing an exception.

Note: I have to send only in this format else please advice the php code that how server programmer can read the request like:

HttpPost httppost = new HttpPost(URL);
JSONObject json = new JSONObject();
try {
    // JSON data:
    json.put("PN", "Products");
    json.put("position", "5th");

    JSONArray postjson=new JSONArray();
    postjson.put(json);

    // Post the data:

    httppost.setHeader("json",json.toString());
    HttpParams ht=httppost.getParams().setParameter("jsonpost",postjson);
    String s=ht.toString();
    // Execute HTTP Post Request

    HttpResponse response = httpclient.execute(httppost);

try replacing json.tostring() here:

httppost.setHeader("json",json.toString());

replace it with "application/json"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM