如何使用android java将post数据传递到php代码?
我有以下url和数据 网址: 输入数据格式:如何使用android java将post数据传递到php代码?,java,php,android,Java,Php,Android,我有以下url和数据 网址: 输入数据格式: {"data":{"customer_name":"ass","hotel_id":"6","mobile_no":"999966632"}} 可能吗?如果是,我如何传递此数据 我的尝试: List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("custom
{"data":{"customer_name":"ass","hotel_id":"6","mobile_no":"999966632"}}
可能吗?如果是,我如何传递此数据
我的尝试:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("customer_name", "ass"));
nameValuePairs.add(new BasicNameValuePair("hotel_id", "6"));
nameValuePairs.add(new BasicNameValuePair("mobile_no", "999966632"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
List name-valuepairs=new-ArrayList(2);
添加(新的BasicNameValuePair(“客户名称”、“ass”);
添加(新的BasicNameValuePair(“hotel_id”,“6”));
添加(新的BasicNameValuePair(“手机号”,“9999632”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
但在php端,我只能像这样访问它
“{”customer\u name:“ass”,“hotel\u id:“6”,“mobile\u no:“9999632”}”
你需要使用类似截击的东西-
为什么它对你没有帮助?您是否尝试在那里实现代码,如果是,请分享您可能遇到的错误。您在哪里提到{“数据”:?objectSee更新的答案。然后我将只传递JsonObject而不是新的JsonObject(参数)
HashMap<String, String> params = new HashMap<String, String>();
params.put("customer_name", "ass");
params.put("hotel_id", "6");
params.put("mobile_no", "999966632");
String YourURL = "http://......com/hotel/api/customerapi/customer_register?APIKEY=9ffeb408h93053dc0e59a0c3f8814bcb8df30b69";
JsonObjectRequest request_json = new JsonObjectRequest(YourURL, new JSONObject(params)),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
//Do what you want on response
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//If there's an error...
}
});
//Add process to queue to get JSON in background thread
queue.add(request_json);
JsonObject jo = Json.createObjectBuilder()
.add("data", Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("etc", "etc")
.add("etc", "etc")))
.build();