Anusha
Anusha

Reputation: 243

Posting a request based on webservice in Android

I am beginer to work with WebServices

 Method Type: POST

 Request Parameters :  {loginid:'[email protected]', password:'yyyyy'}

I was tried like below:

  JSONObject jObj = new JSONObject();
  try {
    jObj.put("loginid", email.getText());
    jObj.put("password", password.getText());
}

how can i write the JSON code for it.

Upvotes: 2

Views: 43

Answers (1)

Kanaiya Katarmal
Kanaiya Katarmal

Reputation: 6108

JSONObject jObj = new JSONObject();
try {
    jObj.put("loginid", email.getText());
    jObj.put("password", password.getText());
}

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("www.yoursite.com/page");
StringEntity se = new StringEntity(jObj.toString());  
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
post.setEntity(se);
client.execute(post);

Upvotes: 2

Related Questions