【发布时间】: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