【发布时间】:2015-06-01 09:34:48
【问题描述】:
我需要使用以下设置通过 HTTP POST 将 XML 字符串发送到另一台服务器...
POST /xmlreceive.asmx/CaseApplicationZipped HTTP/1.1
Host: www.dummyurl.co.uk
Content-Type: application/x-www-form-urlencoded
Content-Length: length
XMLApplication=XMLstring&byArray=base64string
我猜我需要通过cURL 或fsockopen 进行设置。
我已经尝试了以下方法,但没有成功。
$url = "http://www.dummyurl.co.uk/XMLReceive.asmx/CaseApplicationZipped";
$headers = array(
"Content-Type: application/x-www-form-urlencoded"//,
);
$post = http_build_query(array('XMLApplication' => $XML, 'byArray' => $base64));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "response: ".$response;
远程服务器给出以下响应...
"Object reference not set to an instance of an object."
【问题讨论】:
-
但是 $response 打印了什么?也许您可以像他说的那样打印错误(使用 curl_error()):stackoverflow.com/a/1234556/1919749
-
我认为您不应该在
$headers中添加POST行。不是header,是HTTP请求,是cURL基于CURLOPT_POST自动完成的。 -
我现在已经更改了 POST 行,我现在得到这个响应...“无法转换为 System.Byte。参数名称:类型 ---> 输入字符串不正确格式。”
标签: php curl http-headers http-post