I am sending a get request with one parameter in JSON
which is set into request body, but don't know how.
Are there any particular methods for this?
Asked
Active
Viewed 981 times
0

elfar
- 461
- 2
- 6
- 21
3 Answers
0
Basically to send JSON with HTTP you use POST requests, and the JSON string is part of the request body.
You cannot append JSON to the URL since the JSON delimiters are illegal characters and even if you use escape characters, this is not the way it should be done.
If you need some examples, there are several questions here:
send JSON to server via HTTP put request in android
Transfer JSON to server in post request
Good luck!
0
Try this code for send get request -
ArrayList<NameValuePair> perameters = new ArrayList<NameValuePair>();
perameters.add(new BasicNameValuePair("param1", "value1"));
perameters.add(new BasicNameValuePair("param2", "value1"));
perameters.add(new BasicNameValuePair("param3", "value1"));
perameters.add(new BasicNameValuePair("param4", "value1"));
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(perameters, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet("your basic url excluding ? mark");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
responseBody = EntityUtils.toString(httpEntity);
JSONObject jsObject = new JSONObject(responseBody);
Hope this code help you!!!1 if it is not working please let me know i will try to help you more.

shweta_jain
- 453
- 1
- 5
- 19
-
You can send one parameter using this method also.. Can you please post WEbservices URL . so that i can understand more. – shweta_jain Apr 28 '14 at 04:32
0
HttpPost post = new HttpPost(url);
post.setHeader("Content-type", "application/json");
InputStream resultStream = null;
HttpResponse response = null;
StringBuilder entityStringBuilder = new StringBuilder();
try {
HttpClient client =new DefaultHttpClient();
JSONObject dateObject = new JSONObject();
dateObject.put("CurrentTime", UTCDate.GetUTCdatetimeAsString());
StringEntity currentDate = new StringEntity(dateObject.toString());
post.setEntity(currentDate);
//post.setEntity(dateObject);
response = client.execute(post);
resultStream = response.getEntity().getContent();
please change according to your needs.........

Anil Kashyap
- 71
- 6