2016-08-18 5 views
0

GAEでGET HTTPリクエスト中アプリケーションを作成するにはどうすればよいですか?私はそれをハンドラ関数として持ちたくないので、レスポンスボディを取得するために必要なURLがあります。中間アプリケーションを取得する方法

答えて

0

これがうまくいかない場合、私はそれほど謝りません。 GAE's docsによると、あなたはおそらく(contextパッケージがリリースされたばかりのゴー1.7に標準でN.B.)のような*http.Client何かを得るためにurlfetchを使用したい:

import (
    "context" // Go 1.7 
    // "golang.org/x/net/context" // Go < 1.7 
    "google.golang.org/appengine/urlfetch" 
) 

client := urlfetch.Client(context.Background()) 
resp, err := client.Get("http://example.com/") 
1

urlfetchパッケージを使用してください。

ctx := appengine.NewContext(r) // r is the *http.Request arg to the handler 
client := urlfetch.Client(ctx) 
resp, err := client.Get("http://example.com") 
if err != nil { 
    // handle the error 
} 
body := resp.Body // body is an io.Reader containing the response body 

Here's a complete example