2

I am having some problems with what should be a rather simple task. I simply need a JSON array with a single JSON object within it to be posted to my webservice. The entire URL request needs to be formatted like this:

http://www.myserver.com/myservice.php?location_data=[{"key1":"val1","key2":"val2"....}]

  • I think you need to use POST method for this – krishna Apr 08 '13 at 06:07
  • What you describe with your URL example is a GET not a POST. GET means that the information is passed in the url, and POST means that the information is passed to the web service via the body of the request. More importantly though, what is the actual problem you're having? – Rich Apr 08 '13 at 06:07

2 Answers2

3
try {

            HttpClient httpclient = DefaultHttpClient();

            HttpGet httpget = new HttpGet(URL+"?location_data="+JSONARRAY);

            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();


        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection " + e.toString());
        }
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
  • Thanks for ur answer i got it,i am very much beginner for json,and just learning things....can u give me any webservice address where i can test this –  Apr 08 '13 at 07:22
0

Orginally from here

 HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(
        "http://www.myserver.com/myservice.php"
        );

httpPost.setHeader("content-type", "application/json");



JSONObject locationData = new JSONObject();

locationData .put("key1", "val1");
locationData .put("key2", "val2");


StringEntity entity = new StringEntity(locationData.toString(), HTTP.UTF_8);
httpPost.setEntity(entity);

HttpResponse response = httpClient.execute(httpPost);
Community
  • 1
  • 1
Nezam
  • 4,122
  • 3
  • 32
  • 49
  • ya brother i red it before but i don't got it ...thats why i posted this question so that i can get something latest and easy...thanks for ur response –  Apr 08 '13 at 07:24