我刚开始使用Web服务
Method Type: POST
Request Parameters : {loginid:'xxxx@gmail.com', password:'yyyyy'}
我的尝试如下:
JSONObject jObj = new JSONObject();
try {
jObj.put("loginid", email.getText());
jObj.put("password", password.getText());
}
我该如何为它编写JSON代码。
答案 0 :(得分:2)
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);