send HTTP POST to the other URL with Basic Authorization by php cURL
IPFS
主要重點在
1) 產生 postdata array
2) 檢查 response http status code
3) curl_options
$tourl = "http://YOUR_TARGET_POST_URL";
$ch = curl_init();
$img1 = curl_file_create($path_to_image_1);
$img2 = curl_file_create($path_to_image_2);
$postdata = array(
"img1"=>$img1,
"img2"=>$img2
);
$curl_options = array(
CURLOPT_URL=>$tourl,
CURLOPT_HTTPHEADER => array(
"authorization: Basic YmVpamXXXXXXXXXXXXXXXXXX",
"cache-control: no-cache"
),
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$postdata,
CURLOPT_HEADER=>1,
CURLOPT_USERPWD=>"username:password",
CURLOPT_RETURNTRANSFER=>true
);
curl_setopt_array($ch, $curl_options);
$return_value = curl_exec($ch);
$err = curl_error($ch);
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Original link: Phanix's Blog
喜欢我的作品吗?别忘了给予支持与赞赏,让我知道在创作的路上有你陪伴,一起延续这份热忱!
