【问题标题】:POST Base64 encoded data in PHP在 PHP 中发布 Base64 编码数据
【发布时间】:2010-11-17 16:28:51
【问题描述】:

我需要使用 cURL POST 一些数据到 PHP 页面,请求包含三个参数:

  • 其中两个是常规文本值
  • 一个是Base64编码文件

我注意到 Base64 值在传输过程中损坏。

这是发送请求的代码:

$filename = "img2.jpg"; //A sample image file
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$base64 = base64_encode($data);

$postData = "id=1234&sometext=asdasd&data=" . $base64;

$ch = curl_init("http://mydomain/post.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$httpResponse = curl_exec($ch);
curl_close($ch);

有什么建议吗?

【问题讨论】:

    标签: php post base64 httprequest


    【解决方案1】:

    也许您应该使用urlencode(),因为+= 在base64 字符串中?

    【讨论】:

      【解决方案2】:

      确保发布数据的大小不超过 php.ini 文件中的“max_post_size”。

      【讨论】:

        【解决方案3】:

        一个合理的猜测是编码添加了 + - 号,这会弄乱您的数据。

        编码后,尝试将替换+添加到- (当然,在接收时倒退。)

        参考: http://en.wikipedia.org/wiki/Base64#URL_applications

        【讨论】:

          猜你喜欢
          • 2019-06-19
          • 1970-01-01
          • 2011-02-03
          • 1970-01-01
          • 1970-01-01
          • 2013-01-13
          • 2015-07-21
          • 1970-01-01
          • 2013-10-23
          相关资源
          最近更新 更多