• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLConnection -> ProtocolException in Android 4

 
Fooasdsad Baraasdasd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Why I getting ProtocolException: content-length promised 343 bytes, but received 0 in Android 4.x when using URLConnection? while works fine in Android 2.3.3...

Stacktrace:

Code:

What's the problem?
I've searched alot, but couldnt find the solution

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all the information you have about the error? Just its name? No stack trace or description or anything?

Here's a guess, then: I assume the String.format() method doesn't URL-encode the parameter values. Perhaps you should be doing that.
 
Fooasdsad Baraasdasd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, forgot to post it... edited now.


And yea, already tried "URLEncoder.encode(X, encoding)" on those parameters but gives same error.
 
Fooasdsad Baraasdasd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Up... :/
 
Fooasdsad Baraasdasd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SOLVED!

The problem was Content-Lenght . We must let URLConnection set that, instead of setting it manually.

So I removed "_uc.setRequestProperty("Content-Length", Integer.toString(parameters.length()));" and Fixed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic