在PHP中POST POST Base64编码数据

Mar*_*ark 3 php post base64 httprequest

我需要使用cURL将一些数据发布到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);
Run Code Online (Sandbox Code Playgroud)

有小费吗?

Mat*_*Cat 15

也许你应该使用urlencode()因为+=base64字符串?