Doing a POST with cURL but server shows GET
Posted
by
user1798818
on Stack Overflow
See other posts from Stack Overflow
or by user1798818
Published on 2012-11-04T22:47:58Z
Indexed on
2012/11/04
23:00 UTC
Read the original article
Hit count: 172
I am trying to do a simple POST. I am using the code below but when I look at the server log it shows it is doing a POST instead of a GET. Any idea why? Code below.
THanks, Mark
$url = 'http://www.mydomain.com/api.php';
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@path\file.jpg');
$headers = array(
'Content-Type: image/jpeg'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec( $ch );
© Stack Overflow or respective owner