Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

send string data is correct so send? I'm not able to send the request.

$header = str_pad("cccc", 4," ", STR_PAD_RIGHT);
$header .= str_pad("bbbb", 6," ", STR_PAD_RIGHT);

$url ="http://www.xxxxxxxxxx.com";

$ch                 = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $header);
$response_url   = curl_exec($ch);
$erro_curl          = curl_error($ch);
curl_close($ch);

print_r($response_url);
share|improve this question
Not able to? Does your computer shut off? Does your internet connection reset? Do you get any errors, warnings, or notices either on the screen or in your logs? – Crontab Jan 23 at 17:43
Error: Request contains LESS THAN 15 BYTES, I am sending the other fields – user1997072 Jan 23 at 17:47
Sounds like an issue with whoever is providing the service you're trying to consume - you should probably ask them. – Crontab Jan 23 at 17:48
Aren't you supposed to send proper name value pairs in that post? rather than just some plain text – Ø Hanky Panky Ø Jan 23 at 17:49
could you give me an example? – user1997072 Jan 23 at 17:58

closed as too localized by Crontab, cpilko, Frank Shearar, Yoshi, Frank van Puffelen Jan 23 at 20:00

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

If you want to capture the response then you need the CURLOPT_RETURNTRANSFER option:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

Also check your post data is the correct format for what the website is expecting. Normally post data is form encoded, for that you can pass an array:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('first_name' => 'john', 'last_name' => 'smith'));

You may also need to send a Content-Length, Content-Type and possibly a User-Agent header - depending on the third party.

share|improve this answer
Thanks for the help! I'll try again!! – user1997072 Jan 23 at 18:24

Just try it

$header = str_pad("cccc", 4," ", STR_PAD_RIGHT);
$header .= str_pad("bbbb", 6," ", STR_PAD_RIGHT);
$header = array('test'=>$header);

add opt returntransfer

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if you dont add this opt you dont need an echo or print like you do

print_r($response_url);

To capture the variables sent just use $_POST

$_POST['test']
share|improve this answer
Thanks!!!!! But the error continues. – user1997072 Jan 23 at 18:22
Verify if the error is in the destination url. Create a page like 'test.php' and set this page on curopt: curl_setopt($ch, CURLOPT_URL, 'localhost/test.php'); In the destination page just use <?php print_r($_POST['test']); – Gabriel Lucas Jan 23 at 18:28
I've made the two pages and it works fine. Perhaps you don't have the curl extension. In debian or ubuntu just try: $ sudo apt-get install php5-curl – Gabriel Lucas Jan 23 at 18:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.