I need to send some data from my form in html to webservice. (For do this, i need to do the operation of POST)
I have seen research that I can transmit information using php cURL. But in all examples, i don’t view to send data to webservice, only to file php that print $_POST variable.
I have this webservice: http://192.168.1.1/fastfood/event/attendee (example)
And i try to send data in an array.
For example i try to send: attendee = array( 'name' => $_POST['name'] , 'lastname' => $_POST['lastname'] , 'address' => $_POST['address'] );
Then, the web service takes out the array data. ¿How to do this?
UPDATE 1:
This is my code that i’m doing now… But don’t work 🙁
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$attendee = array(
'name' => "$name",
'lastname' => "$lastname",
'address' => "$address"
);
$url_target = 'http://192.168.1.1/fastfood/event/attendee';
//$header = array('Content type: multipart/form-data');
$user = 'root';
$pass = '123';
$userpasswd = "$user:$pass";
$ch = curl_init($url_target);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, $userpasswd);
//curl_setopt($ch, CURLOPT_URL, $url_target);
//curl_setopt($ch, CURLOPT_HEADER, TRUE);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attendee);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
$getInfo = curl_getinfo($ch);
curl_close($ch);
The variable $result return me a FALSE, and the variable $getInfo return me a http_code = 500, Content-Type = Null.
Reading the documentation of cURL when i send a data like a array, the content type should be a “multipart/form-data” but, also, don’t work for me.
Written by Chad Lung at GiantFlyingSaucer