php guzzle请求文件上传并发送正文

时间:2018-10-08 12:15:37

标签: php file post request guzzle

我想发送文件和正文HTTP请求,但API无法响应会导致错误的请求错误

ı响应有误 有两个, 回应状态400 响应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());

结果

  

,内部服务器错误500string(698)“ a:ActionNotSupportedThe带有Action的消息”无法在   接收者,因为EndpointDispatcher的ContractFilter不匹配。   这可能是由于合同不匹配(操作不匹配)   在发送方和接收方之间)或绑定/安全性不匹配   发送者和接收者。检查发送方和接收方是否具有   相同的合同和相同的约束力(包括安全要求,   例如讯息,运输,   没有)。”   NKolayOfiss-MacBook-Pro:soapguzzle nkolayofis $ php index.php,错误   要求400string(0)“”

1 个答案:

答案 0 :(得分:0)

您不能同时使用bodymultipartmultipart在内部形成主体,而body是直接设置HTTP请求主体的选项。将它们混合在一起毫无意义。

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