2014-03-01 28 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

相關問題