【发布时间】:2019-03-13 02:44:27
【问题描述】:
我想用 guzzle 发送文件和正文 HTTP 请求,但 API 未响应收到错误请求错误
我的响应有误 有两个, 状态 400 的响应 response getReasonPhrase() 我收到错误的请求
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
$file="yeni.zip";
$hash=md5_file($file);
$binary=file_get_contents($file);
$soapbody='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://fitcons.com/earchive/invoice">
<soapenv:Header/>
<soapenv:Body>
<get:sendInvoiceRequestType>
<senderID>6310700163</senderID>
<receiverID>53077224954</receiverID>
<docType>XML</docType>
<fileName>newarsiv.xml</fileName>
<hash>'.$hash.'</hash>
<binaryData>'.$binary.'</binaryData>
</get:sendInvoiceRequestType>
</soapenv:Body>
</soapenv:Envelope>';
$client=new Client();
$url="https://earsivwstest.fitbulut.com/ClientEArsivServicesPort.svc";
$options=[
'auth' => ['blabla', 'blabla'],
'headers' => ['Content-Type' => 'text/xml','cache-control'=>'no-control'],
'SOAPAction'=>'sendInvoice',
'body' => $soapbody,
'http_errors'=>false,
'multipart' => [
[
'name' =>"yeni.zip",
'Filename' => "yeni.zip",
'contents' => fopen($file, 'r'),
'headers' => [
'Content-Type' => 'application/zip',
'Content-Disposition' => 'form-data; name="yeni.zip"; filename="yeni.zip"'
]
]
]
];
$response = $client->request('POST', $url,$options);
echo $response->getReasonPhrase()."\n".$response->getStatusCode();
var_dump($response->getBody()->getContents());
结果
,Internal Server Error 500string(698) "a:ActionNotSupportedThe message with Action '' 无法在 接收者,由于 EndpointDispatcher 的 ContractFilter 不匹配。 这可能是由于合同不匹配(不匹配的操作 发送者和接收者之间)或绑定/安全不匹配 发送者和接收者。检查发送方和接收方是否有 相同的合同和相同的约束(包括安全要求, 例如消息,传输, 没有)。” NKolayOfiss-MacBook-Pro:soapguzzle nkolayofis$ php index.php ,坏 请求 400string(0) ""
【问题讨论】:
标签: php file post request guzzle