我必须使用 JSON 对象发送用户名和密码来登录 REST Web 服务。我已经在 android 中完成了以下代码。
HttpClient client = new DefaultHttpClient();
String responseBody;
JSONObject jObj = new JSONObject();
try
{
HttpPost post = new HttpPost("http://localhost:8080/MTA/login");
jObj.put("email", "user@email.com");
jObj.put("password", "password12345");
StringEntity se = new StringEntity(jObj.toString());
post.setEntity(se);
post.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setHeader("Content-type", "application/json");
System.out.println("webservice request executing");
ResponseHandler responseHandler = new BasicResponseHandler();
responseBody = client.execute(post, responseHandler);
System.out.println("Response : " + responseBody);
/*
* You can work here on your responseBody
* if it's a simple String or XML/JSON response
*/
}
catch(Exception e)
{
System.out.println("Exception : " + e);
}
我必须在 iOS 中做同样的事情。我可以在 iOS 中做什么?