如果Android版本低于4,则Android responseCode 400

时间:2013-05-21 21:06:17

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

有人知道我为什么在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();

区别在哪里?

1 个答案:

答案 0 :(得分:0)

好的,我发现了这个post

this ..

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