【问题标题】:php guzzle request file upload and send bodyphp guzzle 请求文件上传和发送正文
【发布时间】: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


    【解决方案1】:

    您不能同时使用bodymultipartmultipart 在内部形成正文,body 是直接设置 HTTP 请求正文的选项。将它们混合在一起没有任何意义。

    在您的示例中,您应该阅读 API 的文档。

    【讨论】:

    • 谢谢,以二进制形式发送,两周前问题已解决
    猜你喜欢
    • 2018-12-04
    • 2020-04-12
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多