Forums Register Login

URLConnection -> ProtocolException in Android 4

+Pie Number of slices to send: Send
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.
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Sorry, forgot to post it... edited now.


And yea, already tried "URLEncoder.encode(X, encoding)" on those parameters but gives same error.
+Pie Number of slices to send: Send
Up... :/
+Pie Number of slices to send: Send
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.
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1865 times.
Similar Threads
Telnet server / multiple readline(s)
Undefined index
how to solve arrayindexoutofbound exception
csv file is not created
error while connecting to webservices
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:55:12.