我使用以下代码将Json对象上传到服务器。
public static User registerUser(User user) {
HttpClient client = null;
client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://www.someurl.com/update/");
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
JSONObject inputJson = new JSONObject();
try {
inputJson.put("name", user.getName());
inputJson.put("username", user.getUsername());
inputJson.put("email", user.getEmail());
inputJson.put("gender", user.getGender());
inputJson.put("location", user.getLocation());
inputJson.put("password", user.getPassword());
inputJson.put("deviceId", user.getDeviceId());
inputJson.put("contactNumber", user.getContactNumber());
inputJson.put("dateOfBirth", user.getDateOfBirth().getTime());
} catch (JSONException e) {
e.printStackTrace();
}
String input = inputJson.toString();
try {
post.setEntity(new StringEntity(input));
} catch (UnsupportedEncodingException e1) {
// handle exception
Log.d("registrattion", e1.getMessage());
}
HttpResponse response = null;
try {
response = client.execute(post);
Log.d("upload", "write");
} catch (IOException e) {
// handle exception
e.printStackTrace();
}
Log.d("res", response.getStatusLine().toString());
return user;
}
服务器未检测到任何Json调用。该代码适用于HTC和Lenovo设备。它也适用于华为设备,这是我国最常用的设备。它不适用于三星设备。可能是什么问题?