使用PHP中的Appengine进行基本身份验证的POST请求 [英] POST request with Basic Authentication from Appengine in PHP

查看:119
本文介绍了使用PHP中的Appengine进行基本身份验证的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中使用Appengine的Basic Authentication发送POST请求?
我已经检查过发布FORM POST请求来源PHP使用HTTP基本身份验证,但解决方案在Appengine环境中不起作用。



请提出任何解决方法。谢谢。

解决方案

您发布的解决方案使用套接字,只有在启用了计费功能后才能工作(请参阅 https://developers.google.com/appengine/docs/php/sockets/ )。 另外,您可以使用file_get_contents和流上下文中设置的Authorization标头( https://developers.google.com/appengine/docs/php/urlfetch/ ),例如

  $ context = 
array(http=>
array(
method=>post,
header=>Authorization:Basic。base64_encode($ username。':'。$ password)。\r\\\

content=> $ data

);
$ context = stream_context_create($ context);
$ result = file_get_contents(url,false,$ context);


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/), 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);

这篇关于使用PHP中的Appengine进行基本身份验证的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆