从下载使用PHP与web服务与浏览器QUOT二进制流的数据;下载的文件被损坏" [英] Download binary stream data from browser using PHP with web service " downloaded file is corrupted "

查看:289
本文介绍了从下载使用PHP与web服务与浏览器QUOT二进制流的数据;下载的文件被损坏"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标:我要让证书并下载

我有以下的场景

在轮廓:

要求的浏览器 - > PHP页面---> PHP REST Web服务--->庆典

request : browser ---> PHP page ---> PHP Rest web service ---> bash

响应的庆典---> PHP REST Web服务---> PHP页面--->浏览器

response : bash ---> PHP Rest web service ---> PHP page ---> browser

在细节:


    从PHP页面名为
  1. REST Web服务做下一篇:

    • 使得证书bash和导出为PFX文件。

    • 从bash的文件作为字节流回报证书。
      hexdump都-b $ exportedcert

  1. REst web service called from php page does next :
    • makes certificate in bash and exports it as pfx file .
    • returns certificate from bash file as byte stream . hexdump -b $exportedcert

从Web服务返回的输出字节(这只是它的一部分):

returned output from web service is bytes (this is just a part of it ):

0000000 060 202 024 071 002 001 003 060 202 023 377 006 011 052 206 110 0000010 206 367 015 001 007 001 240 202 023 360 004 202 023 354 060 202 0000020 023 350 060 202 016 237 006 011 052 206 110 206 367 015 001 007 0000030 006 240 202 016 220 060 202 016 214 002 001 000 060 202 016 205 0000040 006 011 052 206 110 206 367 015 001 007 001 060 034 006 012 052 0000050 206 110 206 367 015 001 014 001 006 060 016 004 010 276 147 122 0000060 363 175 042 303 050 002 002 010 000 200 202 016 130 212 124 302 0000070 271 370 201 316 300 134 133 246 211 062 276 045 241 020 101 155 0000080 057 103 205 232 164 203 265 376 057 067 274 361 057 274 367 110 0000090 251 107 205 130 306 035 267 377 316 223 242 347 363 234 341 052 .....

这里当我叠!我将其转换为二进制后下载此流。我试过很多很多codeS,而我没有得到结果。

here when I'm stacked !! I have to download this stream after converting it back to binary . I've tried many many codes , and I'm not getting results .

  function hex2bin($data) {
        //function URL: http://fiddyp.co.uk/code-to-reverse-a-bin2hex-function/
        //function author: Andy Bailey
        $len = strlen($data);
        for($i=0;$i<$len;$i+=2) {
            $newdata .= pack("C",hexdec(substr($data,$i,2)));
        }
        return $newdata;
    }  

  $api_url = "http://mydomain/certificates";
  try {
   // @url POST /client_cert
     $result = $pest->post('/client_cert', $data);
     $res=explode('"', $result);
     $hex = hex2bin($res[1]);
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=hex.crt");
     header("Content-Type: application/octet-stream ");
     header("Content-Transfer-Encoding: binary");*

     // Read the file from disk
    echo $hex;
} catch (Pest_NotFound $e) {
    // 404
    echo "Certificate with Name = " . $certName_pfx . " doesn't exist!";
}


将它添加到浏览器时,证书已损坏或无效。

certificate is corrupted or invalid when adding it to browser .

有什么建议?结果
P.S:我使用 Restler &安培; 害虫库。

any suggestions ?
P.S : I'm using Restler & Pest libraries .

推荐答案

我已经想通了这一点。

I had figured this out .

首先,升级到PHP 5.4。* 使用HEX2BIN并注意 HEX2BIN 输入参数没有在它的任何空间。

first , upgrade php to 5.4.* to use hex2bin and notice that hex2bin input parameters doesn't have any spaces in it .

二,使用 XXD 与选项 -p 来获得十六进制输出从一块没有偏移,然后删除空格输出。

second , use xxd with option -p to get hex output with no offset and then remove spaces from piece of output .

这将很好地工作。

这篇关于从下载使用PHP与web服务与浏览器QUOT二进制流的数据;下载的文件被损坏&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆