user2238699
user2238699

Reputation:

PHP curl_setopt Not Working Properly?

This is my url when i run that url directly to browser that work properly.

http://domainname.com/helloworld/dimond/add?name=abcd&price=1860

this url is run properly but i send request using curl_setopt that is not working. my code like.

$data="?name=$products_name&price=$fltPrice";
$url = 'http://domain.com/helloworld/dimond/add'.$data;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$myfile = curl_exec($ch);

Plase Help.

Thanks,

Upvotes: 2

Views: 6900

Answers (1)

Raptor
Raptor

Reputation: 54212

To send a POST request via cURL, use the following:

$data="?name=$products_name&price=$fltPrice";
$url = 'http://domain.com/helloworld/dimond/add';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);

Upvotes: 2

Related Questions