【问题标题】:Android HTC Sense - Http Request/ Response exceptionAndroid HTC Sense - Http 请求/响应异常
【发布时间】:2012-10-18 20:32:23
【问题描述】:

在模拟器上工作,但是当我尝试使用 HTC Sense 时,我在这段代码的最后一行遇到了异常

url = new URL(urlString);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", 
                "application/json; charset=utf-8");

//Send request
Gson requestGson = new Gson();          
OutputStream wr = connection.getOutputStream();

例外是 java.net.ProtocolException: 不支持 connection.getOutputStream() 的输出;

我正在 API 10 上测试,HTC Sense 上的 Gingerbread(远程调试)。

有人遇到过这个问题吗?

谢谢。 大卫。

【问题讨论】:

  • 哪一行抛出异常?
  • 你用的是什么安卓版本
  • 你还有this problem吗?还是这个问题的一部分?还是……?
  • 更新了描述...恐怕还是有问题!

标签: android


【解决方案1】:

尝试拨打setDoOutput(true)。 POST 请求需要它。您的代码的第一部分将更改为如下所示:

connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", 
            "application/json; charset=utf-8");
connection.setDoOutput(true);

来源:https://groups.google.com/forum/?fromgroups=#!topic/android-developers/2aEYpsZEMvs

另请参阅其他 StackOverflow 答案:What exactly does URLConnection.setDoOutput() affect?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多