在GAE上使用file_get_contents无效标题问题 [英] Using file_get_contents invalid headers issue on GAE
问题描述
我正在开发一个使用php的谷歌应用程序。我需要使用Podio-php API来使用来自跑道的REST服务。但它使用cURL,我知道它不允许在GAE上使用。所以我尝试调整podio-php lib以通过卷曲模拟器使用file_get_contents。在本地正常工作,但是当我部署它时,没有任何工作。我收到以下错误消息:
警告:file_get_contents( https://api.podio.com:443/oauth/token ):
无法打开流:标头无效。必须是字符串。 in
/base/data/home/apps/s~wt-project1/9.374066902612513343/static/curlEmulator.php
on line 167
然后,我没有收到任何回应,它打破了所有的应用程序。
任何人都有问题出现的位置?
以下是调用:
$ options = array(
ssl=>数组(
allow_self_signed=> true,
verify_peer=> false,
),
'http'=>数组
'method'=> $ method,
'header'=> $ this-> getValue(CURLOPT_HTTPHEADER),
'content'=> $ content
)
);
$ context = stream_context_create($ options);
file_get_contents($ this-> CURLOPT_URL,false,$ context);
谢谢!我在Google App Engine上调用HTTPS API时遇到同样的问题。
我找到了一个解决方案问题是标题格式。
我从一个数组切换到一个原始字符串如下:
Before:
$ base64ClientID = base64_encode(SANDBOX_CLIENT_ID。:。SANDBOX_SECRET_ID);
$ context_opts = array(
http=> array(
method=>POST,
header=> array(Accept:应用程序/ json,
内容类型:应用程序/ x-www-form-urlencoded,
授权:基本$ base64ClientID),
content=> grant_type = client_credentials
),
ssl=> array(
allow_self_signed=> true,
verify_peer=> false
)
);
$ context = stream_context_create($ context_opts);
$ result = file_get_contents(...)
之后:
$ base64ClientID = base64_encode(SANDBOX_CLIENT_ID。:。SANDBOX_SECRET_ID);
$ context_opts = array(
http=> array(
method=>POST,
header=>Accept:application / json\r\\\
Content-Type:application / x-www-form-urlencoded\r\\\
Authorization:Basic。$ base64ClientID,
content=>grant_type = client_credentials
ssl=>数组(
allow_self_signed=> true,
verify_peer=> false
)
);
$ context = stream_context_create($ context_opts);
$ result = file_get_contents(...)
解决了我所有的问题问题。
希望这会有所帮助。
I'm developping a google app using php. I need to consume REST service from Podio using the Podio-php API. But it uses cURL and I know it's not allowwed on GAE. So I tried tweaking the podio-php lib to use file_get_contents through a curl Emulator. Works fine locally, but when I deploy it, nothing works. I get this error message:
Warning: file_get_contents(https://api.podio.com:443/oauth/token): failed to open stream: Invalid headers. Must be a string. in /base/data/home/apps/s~wt-project1/9.374066902612513343/static/curlEmulator.php on line 167
And then, I get no responses and it breaks all the app.
Anyone has an idea from where the problems comes?
Here is the call:
$options = array(
"ssl"=>array(
"allow_self_signed"=>true,
"verify_peer"=>false,
),
'http' => array(
'method' => $method,
'header' => $this->getValue(CURLOPT_HTTPHEADER),
'content' => $content
)
);
$context = stream_context_create($options);
file_get_contents($this->CURLOPT_URL, false, $context);
Thanks!
I had the same problem on Google App Engine calling an HTTPS API.
I figured out that the problem was the headers format.
I switched from an array to a raw string as followed :
Before :
$base64ClientID = base64_encode(SANDBOX_CLIENT_ID . ":" . SANDBOX_SECRET_ID);
$context_opts = array(
"http" => array(
"method" => "POST",
"header" => array("Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic " . $base64ClientID),
"content" => "grant_type=client_credentials"
),
"ssl" => array(
"allow_self_signed" => true,
"verify_peer" => false
)
);
$context = stream_context_create($context_opts);
$result = file_get_contents(...)
After:
$base64ClientID = base64_encode(SANDBOX_CLIENT_ID . ":" . SANDBOX_SECRET_ID);
$context_opts = array(
"http" => array(
"method" => "POST",
"header" => "Accept: application/json\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic " . $base64ClientID,
"content" => "grant_type=client_credentials"
),
"ssl" => array(
"allow_self_signed" => true,
"verify_peer" => false
)
);
$context = stream_context_create($context_opts);
$result = file_get_contents(...)
That solved all my problems.
Hope this will help.
这篇关于在GAE上使用file_get_contents无效标题问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!