GAEでGET HTTPリクエスト中アプリケーションを作成するにはどうすればよいですか?私はそれをハンドラ関数として持ちたくないので、レスポンスボディを取得するために必要なURLがあります。中間アプリケーションを取得する方法
0
A
答えて
-2
あなたはドキュメントを読む必要があります。 https://golang.org/pkg/net/http/
import "net/http"
resp, err := http.Get("http://example.com/")
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
Googleのアプリエンジンでは動作しません。 – anonrose