6

HttpURLConnectionwithsetInstanceFollowRedirects(true)とを送信してPOSTいます。次のようなリダイレクト応答を取得します。

HTTP/1.1 302 Found
Server: nginx
Date: Wed, 09 Jan 2013 20:47:56 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 302 Found
Status: 301 Moved Permanently
Location: http://foo.bar/...

そして、JVMが送信する次のリクエストはGET(正しいリダイレクトされたURLへの)リクエストです。また、元のリクエストに追加したHTTPヘッダーの1つを削除しているようです。

参考までに、私はHttpURLConnection直接使用しているのではなく、PlayFrameworkのWSラッパーを使用しています。

私の質問は-これはJava(Sun JVM 1.7.0)の既知の問題ですか?それとも、Play Frameworkのバグでしょうか?

4

2 に答える 2

8

これは Java のデフォルトの動作です。これは、システム プロパティ http.strictPostRedirect=true を設定することで変更できます。

詳細については、Java ソースHttpURLConnection 実装ソースからのこの引用を参照してください。

    /* The HTTP/1.1 spec says that a redirect from a POST 
     * *should not* be immediately turned into a GET, and
     * that some HTTP/1.0 clients incorrectly did this.
     * Correct behavior redirects a POST to another POST.
     * Unfortunately, since most browsers have this incorrect
     * behavior, the web works this way now.  Typical usage
     * seems to be:
     *   POST a login code or passwd to a web page.
     *   after validation, the server redirects to another
     *     (welcome) page
     *   The second request is (erroneously) expected to be GET
     * 
     * We will do the incorrect thing (POST-->GET) by default.
     * We will provide the capability to do the "right" thing
     * (POST-->POST) by a system property, "http.strictPostRedirect=true"
     */
于 2013-01-10T10:47:04.373 に答える
0

別の方法として、サーバーを制御している場合: ステータス コード 307 を使用します。

于 2013-01-10T12:13:06.237 に答える