之前返回空格我使用了一個名爲ViaPost張貼字母爲我的企業網站。我正在使用SoapClient。上傳的文件必須是base64binary格式。我使用下面的代碼,但返回空。BASE64_ENCODE串
$pdf_data = file_get_contents('test.pdf');
$pdf_data = base64_encode($pdf_data);
print $pdf_data;
爲了擴大上述:
POST /viapostcustomer.asmx HTTP/1.1
Host: api.viapost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://api.viapost.com/CreateLetter"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateLetter xmlns="http://api.viapost.com">
<loginToken>string</loginToken>
<name>string</name>
<description>string</description>
<FileContents>base64Binary</FileContents>
<dynamic>boolean</dynamic>
<shareLetterWithGroup>boolean</shareLetterWithGroup>
<returnMessage>string</returnMessage>
<letterID>long</letterID>
</CreateLetter>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateLetterResponse xmlns="http://api.viapost.com">
<CreateLetterResult>boolean</CreateLetterResult>
<returnMessage>string</returnMessage>
<letterID>long</letterID>
</CreateLetterResponse>
</soap:Body>
</soap:Envelope>
<?php
$client = new SoapClient("http://api.viapost.com/viapostcustomer.asmx?WSDL");
$params = array('sUserName'=>'USERNAME','sPassword'=>'PASSWORD','sLoginToken'=>'','sReturnMessage'=>'');
$SignIn = $client->__soapCall('SignIn', array($params));
$sLoginToken = $SignIn->sLoginToken;
$pdf_data = file_get_contents('test.pdf');
$pdf_data = base64_encode($pdf_data);
$params = array('loginToken'=>$sLoginToken,'name'=>'testname','description'=>'testdescription','fileContents'=>$pdf_data,'dynamic'=>'true','shareLetterWithGroup'=>'false','returnMessage'=>'','letterID'=>'');
$CreateLetter = $client->__soapCall('CreateLetter', array($params));
$returnMessage = $CreateLetter->returnMessage;
print $returnMessage;
?>
返回:保存你的文件有問題。請再試一次。
我已經做了一些愚蠢的,我知道我有。
'$ pdf_data'是否爲空? (不'的file_get_contents( '檢驗.pdf');?'返回有效的數據) –
有BASE64_ENCODE之前,你的$ pdf_data變量的內容? – m4t1t0
是的,它的確如此。這是我沒有得到的。我承認我以前從未使用過這兩個命令中的任何一個。 base64_encode是可打印的嗎?感謝回覆 –