在PHP代码中转换curl line命令 [英] convert curl line command in php code

查看:102
本文介绍了在PHP代码中转换curl line命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我在php curl代码中转换curl命令行吗? plz

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

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);


推荐答案

您是否看过其中的 cURL页面 PHP手册吗?保留为此所需的一切。

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

编辑

在代码中,提供了 curl_exec()。如果在调用 curl_exec()后仍然无法使用,请尝试查看 curl_error()

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().

这篇关于在PHP代码中转换curl line命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆