Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 961
Akhilesh Avatar asked Feb 10 '14 00:02

Akhilesh


1 Answers

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);
like image 151
Mars Avatar answered Sep 19 '22 11:09

Mars