0

We are trying to auto populate a form which is having a text area.

<textarea name="myarea"></textarea>

We can do it using curl however it is accepting only the part of the input text. If the content is too large then it accepts nothing. There is no restriction with respect to number of characters on the text area.

$area['myarea']=>"a large html code.................."
curl_setopt($ch,CURL_POSTFIELDS,$area);
curl_execute();

Please suggest the solution.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
Aditya
  • 425
  • 3
  • 8
  • 22
  • What exactly is the problem? How large is large in your case? Can you post specific examples? What happens if you post large data? Are there any error messages? – Pekka Nov 09 '09 at 12:58
  • How large is too large? Can you post the same amount of data if you use the webpage in a browser? It could be that you're hitting the server's post_max_size – NeilCrosby Nov 09 '09 at 13:00
  • The problem is that if there is 2-3 lines of input text then it is working correctly, if there are 4-5 lines then nothing is accepted, there are no error messages. There is no such max size speified on the server. – Aditya Nov 09 '09 at 13:22

1 Answers1

0

Are you sure you escaped the parameter correctly? Just use urlencode() for this purpose. Here is an example:

<?php
$url = 'http://localhost/';

$fields = array (
  'param1' => 'val1',
  'param2' => 'val2'
);

$qry = '';
foreach ($fields as $key => $value) {
  $qry .= $key . '=' . urlencode($value) . '&';
}
$qry = rtrim($qry, '&');

// Alternatively, you can also use $qry = http_build_query($fields, '');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);

var_dump($result);
?>

If you want to verify that the request was send properly, I would recommend netcat. Just set the URL to http://localhost:3333/ and then execute netcat using: $ nc -l -p 3333

As expected, the request looks like this: POST / HTTP/1.1 Host: localhost:3333 Accept: / Content-Length: 23 Content-Type: application/x-www-form-urlencoded

param1=val1&param2=val2
user206268
  • 908
  • 2
  • 8
  • 23