2014-03-01 29 views
0

我想在GAE网站上设置两个PHP:一个充当Web服务层,另一个充当前端。到目前为止,事情很好。我试图保证这两层之间的通信,这样我不仅可以拨打我的网络服务。如何在PHP中为Google App Engine执行URLFetch时禁用重定向?

我发现这篇文章谈到有关提出请求,并通过这样做,它可以设置X-AppEngine上,入站的appid头,这正是我想要的。 https://developers.google.com/appengine/docs/php/urlfetch/#PHP_Making_requests

要做到这一点,文章说我应该“考虑告诉UrlFetch服务在调用它时不要遵循重定向。”;那么马上就不会提供任何关于你如何实际运作的文件DO

我的要求是这样的:

$data = ['data' => 'this', 'data2' => 'that']; 
$data = http_build_query($data); 
$context = [ 
    'http' => [ 
    'method' => 'get', 
    'header' => "custom-header: custom-value\r\n" . "custom-header-two: custome-value-2\r\n", 
    'content' => $data, 
    ] 
]; 
$context = stream_context_create($context); 
$result = file_get_contents('urlgoeshere', false, $context); 

思想&帮助的感谢!

回答

3

两种方式,要么设置follow_location虚假和/或MAX_REDIRECTS 0

$context = [ 
    'http' => [ 
    'method' => 'get', 
    'header' => "custom-header: custom-value\r\n" . "custom-header-two: custome-value-2\r\n", 
    'content' => $data, 
    'follow_location' => false, 
    ] 
]; 

$context = [ 
    'http' => [ 
    'method' => 'get', 
    'header' => "custom-header: custom-value\r\n" . "custom-header-two: custome-value-2\r\n", 
    'content' => $data, 
    'max_redirects' => 0, 
    ] 
]; 
+0

我尝试了这些,但它似乎没有对GAE任何影响头。 – dracolytch

+0

你后面有什么标题? –

+0

** X-Appengine-Inbound-Appid **:当一个应用程序调用另一个应用程序时,Google App Engine标头。您需要关闭重定向功能。来自Google [Documentation](http://developers.google.com/appengine/docs/php/urlfetch/#PHP_Making_requests): _如果您向其他App Engine应用程序发出请求,则应考虑将UrlFetch服务告知调用它时不遵循重定向。 此设置做两两件事: 使呼叫速度 添加包含应用ID的请求的X的AppEngine-入站-APPID头,所以响应的应用程序可确定传入requests._ – dracolytch

相关问题