0

ここにいくつかのポインタが必要です。つまり、基本的に私が行ったことは、Webサーバーへのログインに使用するフォームを作成したことです。したがって、応答コードから、wiresharkを介してステータスコード200を取得できます。このブラウザログインシステムの通常のパスは次のとおりです。

password + id> index.php>(trueの場合)> index2.phpしかし、Androidアプリでは、どうやらリダイレクトされないようですが、それが想定されているかどうかはわかりませんか?Jsoup.connect(URL).cookie(sessionid、理由はわかりませんが、常にnull).get();を使用してみました。ただし、常にnullであるため、機能しません。正しい場合のCookieヘッダーは「PHPSESSID=somenumiericavalue」ですか、それともwiresharkから間違ったものを見ていますか?もう1つ、私が言ったように、Android HTTPログインの質問に従って、Jsoup.connectメソッドとHttpURLConnectionも使用してみましたが、ヘッダーと値を確認する必要がある部分に関しては、失われました:(。

if(response.getStatusLine().getStatusCode() == 200){
                        HttpEntity entity = response.getEntity();
                        Log.d("login", "success!");
                        if(entity != null){
                         cookies = client.getCookieStore();

ポンペがもっと何かをするように言ったとき、私はここで迷子になりました。ここで絶対に負けました。別の部分は、wiresharkを使用する次の部分です。負けました。:(

4

1 に答える 1

0

通常、Cookie は HttpClient によって正しく処理される必要があります。実際のリクエストに使用するのと同じ HttpClient インスタンスを使用してログインするだけでよく、Cookie はすべてのリクエストで維持される必要があります。例として、これは私が使用する特定のログイン シーケンスです。私の場合、ロケーション リダイレクトを成功のシンボルとして使用しますが、代わりに 200 OK ステータス ラインを使用できます。これが true を返す場合、HttpClient インスタンスの Cookie ストアにsessionは適切な Cookie があり、保護された URL に問題なくアクセスできます。

public synchronized boolean login() throws Exception
    {
    HttpGet httpget;
    HttpPost httpost = new HttpPost(base + "auth/login");
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("username", this.username));
    nvps.add(new BasicNameValuePair("password", this.password));
    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    HttpResponse r = session.execute(httpost);

    // verify it succeeded
    HttpEntity entity = r.getEntity();
    Header lhdr = r.getFirstHeader("Location");
    if (lhdr != null) {
        // failed
        System.err.println("Login request failed:");
        if (entity != null && entity.getContentEncoding() != null) {
        dump("Login Request",
             new InputStreamReader(entity.getContent(), entity
                       .getContentEncoding().getValue()));
        }
        return false;
    }
    if (entity != null) entity.consumeContent();    
    return true;
    }
于 2011-07-11T15:15:47.773 に答える