我试图将JSON数据发送到PHP服务。这是我必须传输数据的代码:
public class TransmitRegistrationData extends AsyncTask<JSONObject, JSONObject, JSONObject> {
String url = "http://kreationware.com/phpimp/RegistrationDataReceiver.php";
@Override
protected JSONObject doInBackground(JSONObject... data) {
JSONObject json = data[0];
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppostreq = new HttpPost(url);
StringEntity se = new StringEntity(json.toString());
se.setContentType("application/json;charset=UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
httppostreq.setEntity(se);
HttpResponse httpresponse = httpclient.execute(httppostreq);
} catch (Exception e) { e.printStackTrace(); }
return json;
}
}
我正在填充和构建所述JSON数据
public void buildRegistrationData(String data){
try{
jsonObject.put("registration_data", data);
registrationJsonObject.put("registration_information", jsonObject);
}catch (JSONException e){
e.printStackTrace();
}
}
字符串数据是用户输入的内容。然而,我一直在PHP端收到一个空数组。我发生错误的任何线索?