1

somebody knows why I get the ResponseCode 400 on android 2.x ? In Android 4.x it works and the server returns 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();

Where is the difference?

Alexander Sidikov Pfeif
  • 2,418
  • 1
  • 20
  • 35
  • I'm not exactly sure what your issue is, but 2.x had a different implementation of HttpURLConnection than 4.x does. On 2.x, it's recommended to use HttpClient, while on 4.x, HttpUrlConnection is recommended. Also, why do you convert from a URL to a URI and back to a URL again? Why not just use the first value of the url? – GreyBeardedGeek May 22 '13 at 00:30
  • sorry Url and uri was just a leftover.. of a test. ok if found this post... http://stackoverflow.com/a/8067181/1847899 and this.. (topic: Avoiding Bugs In Earlier Releases) http://developer.android.com/reference/java/net/HttpURLConnection.html – Alexander Sidikov Pfeif May 23 '13 at 10:32

1 Answers1

0

ok i found this post.

and this..

topic: Avoiding Bugs In Earlier Releases

Community
  • 1
  • 1
Alexander Sidikov Pfeif
  • 2,418
  • 1
  • 20
  • 35