USPS Label api图像生成失败

时间:2012-02-06 08:43:28

标签: c# asp.net usps

我在asp.net中使用usps api。发送确认后我收到了回复:

<?xml version="1.0"?>
     <DelivConfirmCertifyV3.0Response>DeliveryConfirmationNumber>420063719101969010386000074165</DeliveryConfirmationNumber>
 <DeliveryConfirmationLabel> 
  

2Q / + MEH / 8IP / wQPSU + zna52BhiD / 1T4YX // 6   FJqEGnDXww / 9U // hEnJuH e9ecC / + GD /   ///// 8EtsMO + IN / Mkcwf + YWMfNp9Eb / + YY / 5gdEb / m04N8wf // 5tP8wf62ww / OVV   G35 + /// FF9 / 8G + 19F9 / 8G / Z9 ///// 4i2236 + z8Tz2fv / S / X2fvr / 7PxeferP3X9n   7zE / Z + /// 7P3 / Z + / CMP + u6V7pNpa7pMMJOl + RA + 6V / 7petpOl9 + 6TaTaX / 7pe2rp   Nrk3rVht / a9q2tra2vanJjtftbX7VteO17W1tfbXtbW1 // tftbW1OXbbF9iUP2KY   pimKYlD9itpivYlD2P2KYraYrYlD4pivYrYpimK // Yr2NimP02w / abwwmEGEGE14   YWGEGF7TYZb / DCYXhhbTczhBhewsMIMIML / 8MLwy3hhBlv9NsPxERERERERERERE   RERERERERERERERERERERERwm239Nw / 1SN / SbYXzWHITN53YyUGR8qiPZ2BZFdJs   Nfvwg11 / CCbDX56B4ovnOtREEU8ukm2v4fQTfoRaTj / B0M / BhJN / 8 +伊比+ aZwz + R   2R8z6c8Z / LmEDL5vI7L5dm2ZjCBmM + Z / LmajJzP5HI0y + fM0Okr / THB / 4QcfqIQc   X8emEwn4QcWEGEHH4TCDQIvoJv / o2P20kbHNzSpGxy7YYLm4SoE8OfmGC0bHLto2   NGxzY0tGto2PcJN / + N / 1207米/ p6f + mnSf6enp6f / punEUm / + + k39qk3V T1 / VVj + t14p   N1a6TpNpP // 96 / DLP /// BFP /小时/ vXj6Tf / J ++ P //// ZWN / 7I + H3 / GGR // 7pe3 /// +   ERV // YP3S / CT / + FT / Pp0myH /// 8 ///纬纱/ zl23 / S / TL / 1 /// 0V / 8iL7S8z9Nv / 3   797fdWv /// 9r5Rve // AB / //为0nm CZ + KbV6 /// X3r73M // bScz02v4WGEvYqGEvbCV   [R // // 9hftfbShhLYrtYYSCdfiExX7FbsUxX sQRH4PYr2Niv2KYpEO9r8INe0Gugw   GWV // abfDC9hBraw0Gkm2viIiIjiIiIiIiIiIiIiIiIpNwvpIJsf4Sb + CSV / PJ + d   lzKgOfilRERAopUQSIFFvkRETOxSb4QcP / Kr5A / OedmPIf + 0307/11111 / YTfReO   AF // H // 2米/ T7F //// //// 7V8ff 9P // nyJyNCz5Zdk5Z0InIIPLmaEEGUQQZ0efIn   I0I6xczQggzSPR6LxHZwj8XZTkfiOzhH49G4uZo8IPLmaEU5E7z7Lx8sW // hBhNB   4QcQ0HhBhB8WEH + E8INBhB6YQf / GEHoMIOMIP9MJ / FoNBhPCeg9vhLXRsaLto1vR   scu2jW9F20XcMKTho2MMLDCRcDRd0a2i7cSoaLuGFry + NjiVDRscvi7 / EqGi4GGF   Jw0a2jW0XA0XA0a3t8EtLSerSfSfdJ + npvp0n / p6bSenp6b3hEfrSenSfpv6en6d   J0np6dJ9v3H + k6Tf9NpN + KTFX / 6TpNpN41pN // X039JN /周/ Wk2k2k6TpN7fO0lW   PJ + P / 8P / X /// 4F / 2rrj + P /////// 5lxGZGmbI0M0z + aF9uFhePC / HSH / 4X // JYP /   + r8L4X /// + OP / jyDEJGa0aCEuk09NP0zszM9k + CZ1X5qpwL + cC / 4YP / zgX // wwf / v9ZmF8kBf ////// h62qNbRraSNbR7aQVGthB / a / 9Eb + YHRG / 5tIN / + iN /// MMf / 6   v6I3 +在//// 8xcwf + bZXn + PPz6dBN9Ok3qgm584z2 / NDD + I + 5 + 9F9 / WB / 9F9 // 8G   // urXRffRff ////// 2 / b0m99JvfCBEf3Sb9v9r9f2fuv7P2UT // X // // 2fi8 v9df   1 //// 2frP3 / Z + / 9 / x19IVrHQh + 390v1bSdL1tJ0u9tL / X9tW0nSv9tL // W0tdtLX   21 / dJ0m1bV0vy + R8vmMu0HtnjQZtnv + vy50Pghl2bzGR3yC9hm2e / GcvtbW17W1t   dtbX + 1 / tbW1bX7XimPtbW17W1 + 1 / + tbW1tbX + L9P8J6f6X n6QQvi9vT + 1 + xKHsUx   WxKHxTFbFMVD9iUPh8NjYpimK9iob + xKHwiONiUP2KYlD / Y4fsUxTGxKHsV / BcSo   bC9GtsJGhj // EQ3 + E + W72QrthI0MeGF + 02GEGFtNzOEGFsIMJ / abfcMt4YQYTC8M   J + tpvYTTeGE1 + GW9 / DCDCDLeGsML0q6f + N6 / SS + m0tIL03tv18RERERERERERERE   RERERERERERHERERERERERERHHj + v8fSb9L + n9Jen79Jv5X6 + F // R / 6X / + KN / X //   0ucj / + CF 4 / CX / + EGH // // H9tf // 0CI pJf6WkiDo / ZJ // FF / + qNnnUNJBbaTaXoJB   F + D3 + r865V4YX // 1X9ql2tr6SC + / 6B / IP // rr2c2KRDjpimKS0Q + ygJtZxxaWt9n   P + // + la7aTXtBr // rSw2ulG2l 4cUxBEfhsZvEREREUmK2KimGxm / mVma47EX / 701   uwtINbIcdU7C + PP / iIiIiIiI0ItiGRFwvQJf0m2vX + k7X // BA // 08LnZIQQYQeXM   0I6xdk5E5ZxnCJ2Xj5atjwg / i0HoMIMJ6QQYT0H1fRdwwgwpOGjW4lQ0bGi7ekjY   0XA0a37 +米/ p0np0nq9JJ6dJ9J + k39aTdN + K + l6TpN / F /// x8Yof / 9 /// H4Xwvx / F   /// Nhez4X / 3 // 8wPojfzPRG / 5mg的//// + I + 5 + 7Rff / F // 2fvr / ev7P3 / BS / 3StLVt   LvVtXS + /一个/ 9ra2trt2tranLNYcvkCRFckyJdGMigQjMvlaKwRTyNkRbIoFJYZ0Mz   PsVw / YqERxsSh7FbsSh7EoexX + uEGvfhB6uE / TTT4YW / hhbCabDC7abDWGF85HFG   54Z + 8UbnXz4xnUzQ0aGjQ + IiIjiIiIiI4j / PN + 3pPfpBvp6en + d0v84ZmYQZHyOz   ZnMuzeeOnMZHYQZHzxnMu9zx5fL5 / NmcyOR / ps4ZzLtTGR2R8vG4 + YQcgmHctHOG   cyOR / I +的EM + edDMzPaTaTaTf9L9NPjT09NK4h + np7af + nHpCE9Pj00wn3p4px + MNP   p /// 21 / RraNDDCm40OJUPRoe81wwtGhxKh + JW / bSRrc2NLQIj0SoYbmwSnEp2jWw   wpEhxKhsNGtzY0tGho1vRraNbH // 8VyFigm0n6Sbp9J / Q / SBP / QTF + GM6 / TI9T9U   09P03TyPgm6 / SdBNyEgJtBN /// DC / + H + nr6H9 / P6 //// b9Mj9d9ViF0nrDD //的/   /// iPORj /////// j9tKP0tD + P82L / 5qce2l8c6Bx ///////////// 2 / d // // OM WB   /////// Oj的// + V /// OjtpTo / GJV // QL / 8Z + dFtL50 + DBWN ////// T1 // + 1 // // 6Tf   16 //////// + z3Zz + 1 / s52uv2v / Z7 / 7Pex2lfzj / 9e19vs9 / 9nOz32e7PbaTaTaX /   bSdfbS / dW0rS9tL8JNpexTaXtqx / f9rFpfYSbS2K3VtLbSbStbW1 / Id7GxUPYr9i   mKioexXxTH + x7TFP7f7HIRxXsUx / sUx7Gxm + KOcVFf9hNPtftBhTjp9r6YXtMLww   n9v9lw3a8NMLa2mFsJhYaw0GviIiIiIiI4iIiIiIiI4hxGxERFIRERERERERERH /   ttpf0rbX + FbbS / 03aXxFthhL7sNftsMJftkM / r7YYhfba + 219sML7hhfLcM2wwud   pMkzKDMGR4qw5riBxG2Q2Rkbjt4yEgYMRNLQOwYLrqvD852v52k / 9EHFWUhdUCI8   gSBd + TR + V + gbY9fqhmnEfxxztFjoG3 // 2 + CI / OP / 9EMsC9Um / 3 + 1 // YNvow / wgwg   zEXj95iI7Lx8j8R2XggyPH7 / PEfs6ETkfiOM / F4 + RoR1i7JyNCCDPETsvHy8uZoR   + I7OEdY8R1i5mhbINQR9L / 9tL48IOP / 3rCD8INBxBEfrCaD0GEGEHhBhPQfFoONB 4QemEHsG30tJsMIMLbS1l9Rd5fQwm0u10bH6Lto1uXjXRdtGtxKhou6LthhI2NFw   NGt8nDRrcvzW9F24lQ0XfkNZO //// PFTF // 6T / TPP / 1aT09N0 + k9Ok / TpPpP09PT   ewbfS // bSjrSbr / 3 // xSbp60nSbptJvH9J0m + tJukm / GtJvZCuQaA / S0m / 2Kr // B   S7Sx /小时/ 2vj // DX //// + H / 7ZwM1vpcf / C //// wvsHH / 8F + WEF + P + Pj2D / 9wYO / ENP   9qar /// + BC + GD96 // wweeC /// 4YP / 2ygM1v / + N // 7aW2lojf4Nzaf + YHTZy / bSbORx4QL9cOq + H661j / X / 9   RUfFbFfxUV + x1XIr + RX8W1 / IsC2OpFcciwLYrimKkVx9Re1xUX4QJJJfeulaIe0l   1qiHG6STpJJXtSKOkmkmkkkkWOkWOkkkmvSpJKkkmE0kklTCaap6YTSTTVOk0wkq   SaYSWEC6pbD69h8dr117Jv / egwmF4YWGF / hrDX7LfVYfw / hhBhfhwwmW8GEHZN4c   MIMLDCDCDsm / BhBIDEgMCBSDQo + Pg0Kc3RhcnR4cmVmDQoyOTM3MA0KJSVFT0YNCg ==

</DeliveryConfirmationLabel>
<ToName>Tom Collins</ToName>
<ToFirm>XYZ CORP.</ToFirm>
<ToAddress1>Suite 4D</ToAddress1>
<ToAddress2>8 WILDWOOD DR</ToAddress2>
<ToCity>OLD LYME</ToCity>
<ToState>CT</ToState>
<ToZip5>06371</ToZip5>
<ToZip4>1844</ToZip4>
<Postnet>06371184408</Postnet>
</DelivConfirmCertifyV3.0Response>

我使用以下代码从其字节生成pdf文件:

 byte[] labelBuffer = encoding.GetBytes("i put here inner string of DeliveryConfirmationLabel");
    string fileSaveLocation = " d:/test.pdf";
    // Save label buffer to file
    FileStream LabelFile = new FileStream(fileSaveLocation, FileMode.Create);
    LabelFile.Write(labelBuffer, 0, labelBuffer.Length);
    LabelFile.Close();

pdf已创建,但pdf的内容未公开原因?任何人都可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

你需要将图像作为Base64String处理,就是这样。

byte[] labelBuffer = Convert.FromBase64String("i put here inner string of DeliveryConfirmationLabel");

我不认为这是一个pdf,它是一个图像。所以请尝试使用此代码:

public Image Base64ToImage(string base64String)
{
  // Convert Base64 String to byte[]
  byte[] imageBytes = Convert.FromBase64String(base64String);
  MemoryStream ms = new MemoryStream(imageBytes, 0, 
    imageBytes.Length);

  // Convert byte[] to Image
  ms.Write(imageBytes, 0, imageBytes.Length);
  Image image = Image.FromStream(ms, true);
  return image;
}

答案 1 :(得分:0)

将其保存为pdf。

  

$ response = curl_exec($ session);

     

$ xml = new SimpleXMLElement($ response);
  $ label_img = $ xml-&gt; DeliveryConfirmationLabel;

     

$ label_title ='label.pdf'; //提供你的文件名

     

$文件=的fopen($ LABEL_TITLE, “W”);

     

的fwrite($文件,BASE64_DECODE($ label_img));

<强>说明: 从USPS api调用收到$ response,用于获取编码标签。只需在变量“$ label_img”中获取此标签,然后将其保存在磁盘上。 $ label_title是要保存的文件的名称。 fopen和fwrite是php命令。