简体   繁体   中英

POST request with Basic Authentication from Appengine in PHP

How to send a POST request with Basic Authentication from Appengine in PHP? I already checked Issue FORM POST Request From PHP using HTTP Basic Authentication but solution is not working in Appengine environment.

Please suggest any workaround. Thanks.

The solution you posted uses sockets, which will only work if you have billing enabled (See https://developers.google.com/appengine/docs/php/sockets/ ).

Alternatively, you could use file_get_contents with the "Authorization" header set in the stream context ( https://developers.google.com/appengine/docs/php/urlfetch/ ), eg

$context =
array("http"=>
  array(
    "method" => "post",
    "header" => "Authorization: Basic " . base64_encode($username.':'.$password) . "\r\n",
    "content" => $data
  )
);
$context = stream_context_create($context);
$result = file_get_contents(url, false, $context);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM