Phanix

Just writing

send HTTP POST to the other URL with Basic Authorization by php cURL

主要重點在
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

Like my work??
Don't forget to support or like, so I know you are with me..

CC BY-NC-ND 2.0

Want to read more ?

Login with one click and join the most diverse creator community.