-1

HttpGet UrlでCookieを送信しようとしています。認証のために、私のサービス(HttpGetによる呼び出し)から受け取ります。Urlで送信しますが、毎回エラーメッセージが表示されます。

のように:"ユーザーは認証されている必要があります"。

次のエラーが発生します。

05-15 10:28:17.623: I/System.out(18393): <root>
05-15 10:28:17.623: I/System.out(18393): <status>0</status>
05-15 10:28:17.623: I/System.out(18393): <error>User must be Authentificated</error>
05-15 10:28:17.623: I/System.out(18393): </root>
05-15 10:28:17.623: I/System.out(18393): response =: org.apache.harmony.xml.dom.DocumentImpl@41bff838
05-15 10:28:17.623: I/System.out(18393): sts value =: 0
05-15 10:28:17.623: I/System.out(18393): print customer actived bid api sts values 1 che...

エラー メッセージが表示された デモのスクリーンショット。ここに画像の説明を入力

誰でもこの問題を解決するアイデアを持っています...

4

1 に答える 1

0

サーバーはSet-Cookie、Cookie を取得して他のすべての要求で送信するために使用する必要があるヘッダーを送信します。ここに小さなデモンストレーションがあります。

String cookie;
private static String cookieHeader = "Cookie";
private static String Header_SetCookie = "Set-Cookie";

public HttpResponse get(String url) {
    HttpGet getMethod = new HttpGet(url);
    DefaultHttpClient hc = new DefaultHttpClient();
    if(cookie!=null) {
        getMethod.addHeader(cookieHeader, cookie);
    }
    HttpResponse response = hc.execute(getMethod);
    Header[] headers = response.getAllHeaders();
    for (int i = 0; i < headers.length; i++) {
        Header h = headers[i];
        if(h.getName().equals(Header_SetCookie)){
            cookie = h.getValue();
        }
    }
    return response;
}
于 2013-05-23T09:05:31.750 に答える