POST request with Basic Authentication from Appeng

2019-06-21 08:10发布

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.

1条回答
Explosion°爆炸
2楼-- · 2019-06-21 08:59

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/), e.g.

$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);
查看更多
登录 后发表回答