Php cURL错误56:发送xml请求时从对等方接收数据时失败
我试图将curl转换为使用guzzle,但收到一个错误Php cURL错误56:发送xml请求时从对等方接收数据时失败,php,guzzle,guzzle6,guzzlehttp,Php,Guzzle,Guzzle6,Guzzlehttp,我试图将curl转换为使用guzzle,但收到一个错误curl错误56:从对等方接收数据时失败。 以下是我到目前为止的情况 curl_test.php正在运行 $username = "admin"; $password= "password"; $request_xml = '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE telco_xml_enq SYSTEM "telco_xml_enq.
curl错误56:从对等方接收数据时失败。
以下是我到目前为止的情况
curl_test.php正在运行
$username = "admin";
$password= "password";
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE telco_xml_enq SYSTEM "telco_xml_enq.dtd">
<person>
<individual>
<user_id>1234</user_id>
<full_name>test</full_name>
</individual>
</body>
</person>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "XML_STRING=" . $request_xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
$response = curl_exec($ch);
return $response;
$username=“admin”;
$password=“password”;
$request\u xml='1
1234
测验
';
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_USERPWD,$username.:'.$password);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_超时,4);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,“POST”);
curl_setopt($ch,CURLOPT_POSTFIELDS,“XML_STRING=”.$request_XML);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Connection:close'));
$response=curl\u exec($ch);
返回$response;
guzzle_test.php不工作
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE telco_xml_enq SYSTEM "telco_xml_enq.dtd">
<person>
<individual>
<user_id>1234</user_id>
<full_name>test</full_name>
</individual>
</body>
</person>';
$client = new Client(["verify"=>false,
"auth"=>["admin","password"
]
]);
$options = [
"headers"=>
["Content-Type"=>"text/xml"],
"body"=>$requestXml
];
$response = $client->request("POST",$url,$options]);
$res = $response->getBody();
$request\u xml='0
1234
测验
';
$client=新客户端([“验证”=>false,
“身份验证”=>[“管理员”,“密码”
]
]);
$options=[
“标题”=>
[“内容类型”=>“文本/xml”],
“body”=>$requestXml
];
$response=$client->request(“POST”、$url、$options]);
$res=$response->getBody();
你能帮我吗
非常感谢您的帮助
谢谢看起来您必须在正文
中使用XML\u字符串
。由于此原因,接收器无法检索值,因此抛出错误
$options = [
"headers"=>
["Content-Type"=>"text/xml"],
"body" => "XML_STRING=".$requestXml
];
您需要使用而不是body
将表单发送到服务器。请尝试下面的代码
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE telco_xml_enq SYSTEM "telco_xml_enq.dtd">
<person>
<individual>
<user_id>1234</user_id>
<full_name>test</full_name>
</individual>
</body>
</person>';
$client = new Client(["verify"=>false,
"auth"=>["admin","password"
]
]);
$options = [
"form_params"=>[
'XML_STRING' => $requestXml,
],
];
$response = $client->request("POST",$url,$options]);
$res = $response->getBody();
$request\u xml='0
1234
测验
';
$client=新客户端([“验证”=>false,
“身份验证”=>[“管理员”,“密码”
]
]);
$options=[
“表格参数”=>[
'XML_STRING'=>$requestXml,
],
];
$response=$client->request(“POST”、$url、$options]);
$res=$response->getBody();
您可以使用debug=>guzzle的true选项吗?