我正在尝试使用curl发送一个url编码的xml字段。除了url之外还有其他方式发送数据吗?因为我尝试了这个,但被抛出“没有设置URL!”错误。
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://setmpos.ykb.com/PosnetWebService/XML');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST /PosnetWebService/XML HTTP/1.1
Host: setmpos.ykb.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Pragma: nocache
Accept-Language: tr
Content-Type: application/x-www-form-urlencoded
Content-Length: ".strlen($url)."
$url");
$response = curl_exec($ch);
if (curl_errno($ch)) {
$message = curl_error($ch);
}
答案 0 :(得分:0)
首先,你正在设置一个POST,但是通过自定义处理程序来完成,当CURL完全能够自己执行POST时,这意味着你并没有真正使用GET查询:
怎么样:
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array_of_fields_to_post);
代替?