【问题标题】:Android responseCode 400 if Android-version lower than 4Android responseCode 400 如果 Android 版本低于 4
【发布时间】:2013-05-21 21:06:17
【问题描述】:

有人知道为什么我在 android 2.x 上得到 ResponseCode 400 吗?在 Android 4.x 中它可以工作并且服务器返回 200。

        URL url = new URL(url_in);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
        url = uri.toURL();
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setRequestProperty("Accept-Encoding", "identity");
        c.setRequestProperty("Accept-Charset", "UTF-8");
        c.setRequestProperty("Content-Type", "text/html");

        c.setConnectTimeout(timeout);
        c.setReadTimeout(timeout);
        c.connect();
        int status = c.getResponseCode();

区别在哪里?

【问题讨论】:

  • 我不确定您的问题是什么,但 2.x 的 HttpURLConnection 实现与 4.x 不同。在 2.x 上,建议使用 HttpClient,而在 4.x 上,建议使用 HttpUrlConnection。另外,为什么要从 URL 转换为 URI 并再次转换回 URL?为什么不直接使用 url 的第一个值?
  • 抱歉,Url 和 uri 只是测试的剩余部分。好的,如果找到这篇文章...stackoverflow.com/a/8067181/1847899 和这个..(主题:避免早期版本中的错误)developer.android.com/reference/java/net/HttpURLConnection.html

标签: android httpurlconnection android-2.2-froyo android-version http-response-codes


【解决方案1】:

好的,我找到了这个post

this..

主题:避免早期版本中的错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2015-08-22
    • 2018-06-21
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多