Forum Moderators: coopster

Message Too Old, No Replies

Curl data submission not working

i couldnt just figure out the issue with the code

         

dewteks

2:23 pm on Feb 3, 2009 (gmt 0)

10+ Year Member



Hello all,
I've tried hard to submit a form values to a url using curl but it seem not to be working.
how do i alter the code please to send sms to the specified url.
when i submit the data below through a form directly to the url, it works but doesnt with curl.
any help will be appreciated

<?
$login = 'demo';
$password = 'demo';
$clientid = 'clientidcode';
$sender = 'Demo Acc';
$message_type = 'TEXT';
$receiver = '1234567890123';
$message = 'This is a test message thru curl';

$formdata = 'login=' . urlencode($login) . '&password=' . urlencode($password) . '&clientid=' . urlencode($clientid) . '&sender=' . urlencode($sender) . '&message_type=' . urlencode($message_type) . '&receiver=' . urlencode($receiver) . '&message=' . urlencode($message);

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:8080/server/sendsms/?');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata);
$response=curl_exec($ch);
curl_close($ch);
print $response;
?>

[edited by: coopster at 2:28 pm (utc) on Feb. 3, 2009]
[edit reason] generalized specfics [/edit]

rocknbil

2:55 am on Feb 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm "pretty sure" you don't need the ? unless your source tells you so, it's not a standard HTTP query string.

It doesn't matter what language you're doing this in, curl will always spit out stats via command line when run. I would venture to guess something in curl is balking at the request, OR the recipient of the request is returning an empty response. An example, if you curl a secure credit card processor, and the request doesn't come from an SSL-enabled site, it will return an empty string, leaving $response blank.

Try running it from the command line . . .

php -f full/path/to/yourscript.php

Barring that, see what you can get from curl_get_info() [us2.php.net]