我想将以下信息传递给 Json 服务。
用户名=m@m.com&密码=mmmmm&apikey=12345&class=用户
我从 json 获取数据。但是如何将上述参数传递给 json 服务。
我放松了下面的代码。但它返回一些java脚本。
public void Sample1()
{
try {
String response;
HttpPost post = new HttpPost(
"url");
post.setHeader(HTTP.CONTENT_TYPE,"application/json" );
List<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("username", "m@m.com"));
nameValuePairs.add(new BasicNameValuePair("password", "mmmmm"));
nameValuePairs.add(new BasicNameValuePair("apikey", "12345"));
nameValuePairs.add(new BasicNameValuePair("class", "User"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient client = new DefaultHttpClient();
HttpResponse resp = client.execute(post);
HttpEntity entity = resp.getEntity();
response = EntityUtils.toString(entity);
Log.v("info",">>>>"+response);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
如果有人知道解决方案。
请帮我。