从android手机发送post消息中的json正文
嘿,我想寄这个 { “经度”:“123.123”, “Lattude”:“55.55” }我的网站没有其他要求从安卓手机截击。这些方法似乎不起作用。有人能帮我吗从android手机发送post消息中的json正文,android,json,rest,http-post,Android,Json,Rest,Http Post,嘿,我想寄这个 { “经度”:“123.123”, “Lattude”:“55.55” }我的网站没有其他要求从安卓手机截击。这些方法似乎不起作用。有人能帮我吗 提前感谢您根据您的问题,您需要向您的站点发送两个参数 这是使用params发送POST数据的截击示例代码 public void PostToServer(String URL, final HashMap Params) { try { RequestQueue queue = Volley.newReque
提前感谢您根据您的问题,您需要向您的站点发送两个参数 这是使用params发送POST数据的截击示例代码
public void PostToServer(String URL, final HashMap Params) {
try {
RequestQueue queue = Volley.newRequestQueue(networkContext);
StringRequest strreq = new StringRequest(Request.Method.POST,URL,
new Response.Listener<String>() {
@Override
public void onResponse(String Response) {
try {
//your server response
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError e) {
e.printStackTrace();
}
}){@Override
public Map<String, String> getParams(){
return Params;
}
};
queue.add(strreq);
} catch (Exception e) {
e.printStackTrace();
}
}
public void PostToServer(字符串URL,最终HashMap参数){
试一试{
RequestQueue=Volley.newRequestQueue(networkContext);
StringRequest strreq=新的StringRequest(Request.Method.POST、URL、,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
试一试{
//您的服务器响应
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公众回应(截击错误){
e、 printStackTrace();
}
}){@覆盖
公共映射getParams(){
返回参数;
}
};
queue.add(strreq);
}捕获(例外e){
e、 printStackTrace();
}
}
然后像这样调用这个函数
HashMap<String, String> params = new HashMap<>();
params.put("Longitude", "12.123");
params.put("Lattitude", "12.145");
PostToServer("http://example.com/send.php", params);
HashMap params=newhashmap();
参数put(“经度”,“12.123”);
参数put(“latitude”,“12.145”);
PostToServer(“http://example.com/send.php“,参数);
请添加代码片段并发布堆栈跟踪。