[英]Curl PUT in PHP
I need to "translate" this curl in php, but I can't do it:我需要在 php 中“翻译”这个 curl,但我做不到:
curl --proxy proxy_ip:port --proxy-user user:psw- --user "admin":"admin" \
-H 'Content-type: application/json' -X PUT \
-d '{"installInHw":"true", "name":"flow1", "node": {"id":"00:00:00:4e:54:32:33:0f", "type":"OF"}, "ingressPort":"2", "etherType": "0x800", "protocol": "6", "tpDst": "80", "priority":"65535","actions":["DROP"]}' \
'indirizzo_http'
Can anybody helps me?有人可以帮助我吗?
PHP curl has these options to proxy requests. PHP curl有这些选项来代理请求。
// $data = '{"installInHw":"true", "name":"flow1", "nod" ... ;
//$loginpassw = 'admin:admin';
//$proxy_ip = '192.168.0.50';
//$proxy_port = '8080';
//$url = 'http://example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
if(!$response) {
return false;
}
Thanks everybody!谢谢大家! I solved the problem adding this:我解决了这个问题:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.