我发送请求到服务器
public HttpResponse post(String URN, String entity) throws IOException {
HttpPost httpPost = new HttpPost(URL + URN);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("Accept", "application/json");
httpPost.setEntity(new StringEntity(entity, HTTP.UTF_8));
return httpClient.execute(httpPost, httpContext);
}
要创建新帐户,会向服务器发送电话号码并进行验证。如果数字无效,则返回400 BAD REQUEST错误。
在服务器的响应中,在内容中返回JSON对象。这具有返回400错误的原因的详细信息。典型的JSON响应看起来像这样
{"dev_message": "The number 93015205229804 isn't a valid mobile number.", "user_message": "Invalid phone number", "error_code": 108}
当返回400错误时,execute方法抛出IOException。如果自动抛出错误,如何从HttpResponse获取消息?