我正在尝试以查询字符串格式(例如:url?values)向服务器发送http请求到服务器并在我的Android设备上获取响应。
但HttpPost httppost = new HttpPost(URL);
正在抛出异常。
注意:我必须只发送这种格式,否则请建议php代码,服务器程序员可以如何读取请求:
HttpPost httppost = new HttpPost(URL);
JSONObject json = new JSONObject();
try {
// JSON data:
json.put("PN", "Products");
json.put("position", "5th");
JSONArray postjson=new JSONArray();
postjson.put(json);
// Post the data:
httppost.setHeader("json",json.toString());
HttpParams ht=httppost.getParams().setParameter("jsonpost",postjson);
String s=ht.toString();
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
答案 0 :(得分:0)
尝试在此处替换json.tostring():
httppost.setHeader("json",json.toString());
将其替换为“application / json”