【问题标题】:Send request and get response from php server for android发送请求并从 php 服务器获取响应
【发布时间】:2011-10-06 10:22:57
【问题描述】:

我正在尝试以查询字符串的格式(例如: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);

【问题讨论】:

  • 抛出了什么异常?
  • 抛出异常invokespecial java.lang.RuntimeException(java.lang.String)
  • 也是一个错误/AndroidRuntime(8647):at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  • 如果您可以将整个堆栈跟踪添加到您的问题中会有所帮助。

标签: php android json url


【解决方案1】:

尝试在此处替换 json.tostring():

httppost.setHeader("json",json.toString());

将其替换为“应用程序/json”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多