簡體   English   中英

cURL到PHP中的JSON-POST無法正常工作

[英]cURL to JSON in PHP - POST not working

我有以下cURL命令,可將圖像添加到我的服務器,效果很好:

curl -i -X POST -u user:pw -F 'post[image]'=@image.jpg http://domain.com/post.json

現在,我想用PHP進行這項工作。 除了“ post [image]” = @ image.jpg部分,我似乎一切正常。

要傳遞給curl_setopt($ch, CURLOPT_POSTFIELDS)字段curl_setopt($ch, CURLOPT_POSTFIELDS)我需要什么? 有人可以幫我嗎?

$url = 'host/script.php';
$post = array('image' => '@image.jpg');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM