0

I want to send the below JSON request to a web service and read the response.

{"Email":"aaa@tbbb.com","Password":"123456"}

I know to how to read JSON. The problem is that the above JSON object must be sent in a variable name json.I want to send Json object as a parameter with get request.

 HttpParams httpParams = new BasicHttpParams();
 HttpConnectionParams.setConnectionTimeout(httpParams,TIMEOUT_MILLISEC);
 HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);

 HttpClient client = new DefaultHttpClient(httpParams);
 HttpGet httpget = new HttpGet(FinalURL.toString());

 //HttpPost request = new HttpPost(serverUrl);
 HttpClient httpclient = new DefaultHttpClient();

 HttpResponse response = client.execute(httpget);
 HttpEntity entity = response.getEntity();

How can I do this from android? What are the steps such as creating request object, setting content headers, etc.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
osum_Dev
  • 1
  • 2
  • See this: http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests – Anid Monsur Feb 10 '14 at 05:02

2 Answers2

0

You can set request using:

httpget.setEntity(new JSONObject(requestString));
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

One of the options i'm using right now is RequestParams:

It can be implemented as:

RequestParams rp = new RequestParams();
rp.put("Email", "aaa@tbbb.com");
rp.put("Password", "123456");
Utils.client.get(url, rp, new AsyncHttpResponseHandler() {
//or your http code

http://loopj.com/android-async-http/doc/com/loopj/android/http/RequestParams.html
http://loopj.com/android-async-http/

Pararth
  • 8,114
  • 4
  • 34
  • 51