user699822
user699822

Reputation: 31

convert curl line command in php code

can anyone help me to convert that curl comand line in a php curl code ? plz

curl -v --data "WSCommunityStringRW?2=1200ve50set&Submit=Submit" http://xxxxx/123 -u "admin:a1s2d3" --anyauth


Yes.I did something but ... not work :(

$api_url  = 'xxx/123';
$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, "admin:a1s2d3");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'WSCommunityStringRW?2' => '1200ve50set',
    'Submit' => 'Submit'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_close($ch);

Upvotes: 0

Views: 1054

Answers (1)

Arjen
Arjen

Reputation: 1321

Have you taken a look at the cURL pages in the PHP manual? It should contain everything you need for this.

Edit

In the code you've provided, curl_exec() is missing. If it doesn't work after calling curl_exec(), try looking at the output of curl_error().

Upvotes: 3

Related Questions