脚本宝典收集整理的这篇文章主要介绍了如何在PHP中发送没有请求数据的cURL POST?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
注意:有角括号代表占位符.@H_360_7@
在终端中,使用以下代码将为我提供所需的响应.
curl -u <user>:<pass> -H 'Content-tyPE: application/XMl' -X POST https://<rest of url>
我当前的PHP看起来像这样:
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$uri); //$uri is the same that I use in terminal curl_setopt($ch,CURLOPT_USERPWD,sPRintf('%s:%s',$user,$pass)); //same as terminal user & pass curl_setopt($ch,CURLOPT_RETURNtransfer,1); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); $headers = array( 'Content-Type: application/xML',//expect an xml response ); curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); $curl_result = curl_exec($ch);
详细信息:
> POST <same url> HTTP/1.1 Authorization: Basic YWRtaW5Ac3BhCMS0NTEuY29tOnNwYXJrc29tZXRoaW5n Host: <correct host> Accept: */* Content-Type: application/xml Content-Length: -1 Expect: 100-continue * HTTP 1.0,assume close after body < HTTP/1.0 400 Bad request < Cache-Control: no-cache < Connection: close < Content-Type: text/html
为什么我在使用PHP时遇到400 Bad Request错误,但在使用命令行时却没有?如何解决此问题,以便使用PHP获得所需的响应?
以上是脚本宝典为你收集整理的如何在PHP中发送没有请求数据的cURL POST?全部内容,希望文章能够帮你解决如何在PHP中发送没有请求数据的cURL POST?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。