我與Endicia航運標籤服務器嘗試。下面的示例代碼允許我從他們的測試服務器獲取USPS標籤。我將如何顯示正在返回的圖像。現在print_r函數(如果未註釋掉)確實打印出看起來像是圖像的數組內容。打印GIF從一個變量PHP
<?php
$strGetLabelURL = "https://www.envmgr.com/LabelService/EwsLabelService.asmx/GetPostageLabelXML";
$request = '<LabelRequest ImageFormat="GIF" Test="YES">
<RequesterID>abcd</RequesterID>
<AccountID>123456</AccountID>
<PassPhrase>samplePassPhrase</PassPhrase>
<MailClass>FIRST</MailClass>
<DateAdvance>0</DateAdvance>
<WeightOz>1</WeightOz>
<Stealth>FALSE</Stealth>
<Services InsuredMail="OFF" SignatureConfirmation="OFF" />
<Value>0</Value>
<Description>Sample Label</Description>
<PartnerCustomerID>12345ABCD</PartnerCustomerID>
<PartnerTransactionID>6789EFGH</PartnerTransactionID>
<ToName>Ben Franklin</ToName>
<ToCompany>United States Postal Service</ToCompany>
<ToAddress1>12345 Main Street</ToAddress1>
<ToCity>Camas</ToCity>
<ToState>WA</ToState>
<ToPostalCode>98607</ToPostalCode>
<ToPhone>2025551212</ToPhone>
<FromName>Technical Support</FromName>
<FromCompany>DYMO Endicia</FromCompany>
<ReturnAddress1>385 Sherman Ave.</ReturnAddress1>
<FromCity>Palo Alto</FromCity>
<FromState>CA</FromState>
<FromPostalCode>94306</FromPostalCode>
<FromZIP4>1864</FromZIP4>
<FromPhone>8005763279</FromPhone>
</LabelRequest>';
$params = array('http' => array(
'method' => 'POST',
'content' => 'labelRequestXML='.$request,
'header' => 'Content-Type: application/x-www-form-urlencoded'));
$ctx = stream_context_create($params);
$fp = fopen($strGetLabelURL, 'rb', false, $ctx);
if (!$fp)
{
print "Problem with $strGetLabelURL";
}
$response = stream_get_contents($fp);
if ($response === false)
{
print "Problem reading data from $url, $php_errormsg";
}
print_r($response);
?>
什麼是$響應的內容? – xdazz
圖像的blob是數組元素嗎? – alex