• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URLConnection -> ProtocolException in Android 4

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Up... :/
 
Fooasdsad Baraasdasd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic