php curl content type,PHP cURL Content-Type未设置

我有一个简单的Web服务,我想连接。为了发布一些在Web服务端正确进行的XML,我需要准备一个适当的请求。我这样使用cURL:

try {

$ch = curl_init();

if (FALSE === $ch)

throw new Exception('failed to initialize');

curl_setopt($ch, CURLOPT_URL,"192.168.1.37");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

'Content-Type: application/xml',

'Connection: Keep-Alive'

));

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

curl_setopt($ch, CURLOPT_PROXY, '');

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);

curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect: "));

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POSTFIELDS,$xml);

$request= curl_getinfo($ch);

var_dump($request);

$content = curl_exec($ch);

if (FALSE === $content)

throw new Exception(curl_error($ch), curl_errno($ch));

} catch(Exception $e) {

trigger_error(sprintf(

'Curl failed with error #%d: %s',

$e->getCode(), $e->getMessage()),E_USER_ERROR);

}

一切都可以。首先我从curl_getinfo($ ch)显示请求体;然后我显示$ content变量的响应。

只有对请求发送到服务器的限制是Content-Type头 – 它必须是应用程序/ xml,否则服务器将回应错误(这不是我的想法,我不能做任何事情)

这里是输出请求:

array(21){[“url”] => string(68)“192.168.1.37”[“content_type”] => NULL [“http_code”] => int(0)[“header_size”] => int(0)[“request_size”] => int(0)[“filetime”] => int(0)[“ssl_verify_result”] => int(0)[“redirect_count”] => int(0)[“total_time”] => float(0)[“namelookup_time”] => float(0)[“connect_time”] => float(0)[“pretransfer_time”] => float(0)[“size_upload”] => float(0)[“size_download”] => float(0)[“speed_download”] => float(0)[“speed_upload”] => float(0)[“download_content_length”] => float(-1)[“upload_content_length”] => float(-1)[“starttransfer_time”] => float(0)[“redirect_time”] => float(0)[“certinfo”] => array(0){}}

响应是HTTP 400错误请求

我可以看到的是[“content_type”] => NULL但我设置这个变量在我的PHP代码…

谁能告诉我我失踪了什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值