0

I have a method which takes a very long string, 90,860 characters and passes this to a PHP page which is then inserted into a database. I've read that there isn't a limit on the size of a PHP post upto about 8mb. I'm assuming that this length of string should be ok.

    msg = URLEncoder.encode(stringToEncode.toString(),"UTF-8"); 

        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://mysite.com/insert.php?data="+msg);
        HttpResponse response1 = httpclient.execute(httpPost);

I know that this works as I can insert short plain strings.

On my PHP page I just get the post data like:

    $data = $_GET['data'];

And insert it. Do I need to add some extra php to de-code the post message? I read that it should be done automatically by PHP.

The problem is that with the long string I either get a 500 error or if I take the string and put it in my browser I just get a page not available.

Thanks in advance!

James MV
  • 8,569
  • 17
  • 65
  • 96

2 Answers2

3

In the Java program you should not pass your data, especially when it is long, in the URL, see this question for example code how to properly pass Post parameters

From PHP side, you should use $data = $_POST['data'];

Community
  • 1
  • 1
iTech
  • 18,192
  • 4
  • 57
  • 80
1

The limiting factor will be the maximum allowed length of an URL that the server is willing to accept. I can't remember if there's some minimum all servers must support, but tests we did a while ago showed that depending on server type the URL length limit was commonly between 2k and 10k characters - this seems to be confirmed by Paul Dixon's extensive answer to this question.

To circumvent this limitation, use multipart post

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79