0

I am posting a string to server. If string size is up to 6000KB then its posted successfully. But when size exceeded more than this its showing response -1.

I have tried method of posting: syn_data1 is string . records fetch from data base and then appending to A string builder and finally i create synData1 string from String builder

URL url = new URL(syn_data1);
URLConnection urlc = url.openConnection();
HttpURLConnection huc = (HttpURLConnection)urlc;
huc.setRequestMethod("POST");
huc.setConnectTimeout(3000);
huc.connect();
int response = huc.getResponseCode();

I do care about each special character and remove.But I did not get success

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87

3 Answers3

3

In theory, the URI in an HTTP request can be of any length, but the practical limit is on the order of 2k. Please read here for more info on that.

I am assuming the length is coming from the query string parameters (those name=value pairs that come after the ?). You should be putting these in the POST data, leaving the path part of the URI only. Of course, the server will have to be looking for those parameters in the POST data as well.

Community
  • 1
  • 1
e.dan
  • 7,275
  • 1
  • 26
  • 29
1

Are you passing the NameValue pairs properly . This is one successful way which i use .

 List<NameValuePair> loginParams = new ArrayList<NameValuePair>(1);
 loginParams.add(new BasicNameValuePair("ColumnName In DB",YourString));

then you do

httppost.setEntity(new UrlEncodedFormEntity(loginParams));

and proceed to execute

Saiesh
  • 641
  • 2
  • 7
  • 23
  • @E.dan and @ Saiesh: i am passing namevalue properly but my problem is that im changing my string into json format and now second code in my question telling invalid parameter – Tofeeq Ahmad Nov 01 '11 at 08:52
  • [Try something like this example for XML - should be pretty similar](http://stackoverflow.com/questions/2559948/android-sending-xml-via-http-post-soap/2560129#2560129) – e.dan Nov 01 '11 at 08:58
  • @E.dan: i request that have a look on my question now.I precise it – Tofeeq Ahmad Nov 01 '11 at 12:50
  • @AndroidDeveloper: sorry, the question is really not clear. What is the URL? What is the data you want to send? Is it name/value pairs, or JSON? What works and what doesn't work? You are missing the critical details and it's really hard to understand what you are trying to do. – e.dan Nov 01 '11 at 12:58
  • records fetch from data base and then appending to A string builder and finally i create synData1 string from String builder – Tofeeq Ahmad Nov 01 '11 at 13:18
1

It's not clear exactly what you're trying to achieve, but this definitely looks wrong:

URL url = new URL(syn_data1.toString());
URLEncoder.encode(syn_data1.toString(),"UTF-16BE");

If syn_data1 is already a string, you don't need to call toString on it.. and calling URLEncoder.encode doesn't have any side-effects, so the second statement is pointless. Perhaps you want:

URL url = new URL(URLEncoder.encode(syn_data1, "UTF-16BE"));

That's just on the encoding side though - you still shouldn't be trying to use enormous URLs. If you have a lot of data, that should be in the body of the request rather than the URL.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • i edited and check already but its also not working.I think its related to string size as if it increase more than 6000 it give responce -1 – Tofeeq Ahmad Nov 01 '11 at 13:15
  • @AndroidDeveloper: As I've said, you shouldn't be trying to include that much data in the URL. It should be part of a post body. Your server will need to understand that, of course. – Jon Skeet Nov 01 '11 at 13:17
  • Sorry but i am clear about it.How can i add it to request body in this code. BTW thank you for time Jon :) can you come to chat please if possible – Tofeeq Ahmad Nov 01 '11 at 13:20
  • @AndroidDeveloper: No, I'm busy trying to do my own work. The first thing you'd need to do is make sure that the server can even *cope* with it as a body. After that, using HttpClient seems like a good idea... – Jon Skeet Nov 01 '11 at 13:27