2011-12-15 12 views
0

ログインする必要があるページにアクセスできるAndroidアプリケーションを作成する作業があります。 私はそのサイトで使用しているPHPコードにアクセスできません。 これはサイトのHTMLソースです:Androidログインアプリケーションを作成するには

<center> 
    <div id="loginWrapper"> 
     <div id="loginBox"> 
      <div id="loginBox-head"></div> 
      <div id="loginBox-title"> 
       <h1></h1> 
      </div> 
      <div id="loginBox-body"> 
       <form id="form-login" action="https://xxxxx.xxxxxx.xxx/index.php?pModule=bG9naW4=&pSub=bG9naW4=&pAct=cHJvY2Nlc3M=" method="post" autocomplete="off"> 
        <label for="aid_username">Username</label> 
        <input type="text" id="username" name="username" value="" onBlur="clearPasswordField();" /> 
        <label for="aid_password">Password</label> 
        <input type="password" id="password" name="password" value="" /> 
        <label> </label> 
        <input type="submit" value="Login" /> 
        <hr /> 
       </form> 
      </div> 
      <div id="loginBox-foot"></div> 
     </div> 
    </div> 
</center> 

私はhttps://xxxxx.xxxxxx.xxx/index.php?pMod ... JvY2Nlc3M =は、私がログインボタンをクリックした場合、それは行く方法であることがわかります。 私はそのURLにアクセスしたとき、ユーザー名とパスワードを入力する必要があります。 URLにユーザー名とパスワードを渡そうとしましたので、次のようになります:https://xxxxx.xxxxxx.xxx/index.php?pMod ... Fzc3dvcmQ =それでも入力する必要があります。 それで、私はソケットパラメータでユーザー名とパスワードを渡すことを知っています。 私は放火犯を使用しようとした(Firefoxのアドオンを)して手動でログインしてこの結果です:

POST index.php?pModule=bG9naW4=&pSub=bG9naW4=&pAct=cHJvY2Nlc3M= 
Params 
----------- 
pAct cHJvY2Nlc3M= 
pModule bG9naW4= 
pSub bG9naW4= 

Headers 
------------- 
Response Headers 
Server nginx/0.7.64 
Date Wed, 14 Dec 2011 19:56:32 GMT 
Content-Type text/html 
Transfer-Encoding chunked 
Connection keep-alive 
X-Powered-By PHP/4.4.8 
Expires Thu, 19 Nov 1981 08:52:00 GMT 
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Pragma no-cache 
Location https://xxxxx.xxxxxx.xxx/index.php?pModule=aG9tZQ==&pSub=aG9tZQ==&pAct=dmlldw== 
Content-Encoding gzip 
Vary Accept-Encoding 

Request Headers 
Host xxxxx.xxxxxx.xxx 
User-Agent Mozilla/5.0 (X11; Linux i686; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language en-us,en;q=0.5 
Accept-Encoding gzip, deflate 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 
DNT 1 
Connection keep-alive 
Referer https://xxxxx.xxxxxx.xxx/ 
Cookie PHPSESSID=ecf5337e2f08bf48537da099b90b8a3f 

Post 
-------- 
Parameters 
password xxxxxx 
username xxxxxx 

source 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 31 
username=xxxxxx&password=xxxxxx 

Response & HTML 
----------------------------- 
Reload the page to get source for: https://xxxxx.xxxxxx.xxx/index.php?pModule=bG9naW4=&pSub=bG9naW4=&pAct=cHJvY2Nlc3M= 

私は2つの異なるコードを試してみたし、それが失敗しました。 これはそれである:私のミスだところ

private void login1(){ 
    BufferedReader in = null; 

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(2); 
    postParameters.add(new BasicNameValuePair("username", user.getText().toString())); 
    postParameters.add(new BasicNameValuePair("password", pass.getText().toString())); 

    try { 
     HttpClient client = new DefaultHttpClient();    
     HttpPost request = new HttpPost("https://xxxxx.xxxxxx.xxx/index.php?pModule=bG9naW4=&pSub=bG9naW4=&pAct=cHJvY2Nlc3M="); 
     UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters); 
     request.setEntity(entity); 

     HttpResponse response = client.execute(request); 
     in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

     StringBuilder buffer = new StringBuilder(); 
     String line = ""; 
     String nl = System.getProperty("line.separator"); 
     while ((line = in.readLine()) != null) { 
      buffer.append(line + nl); 
     } 
     in.close(); 

     TextView txt = (TextView) findViewById(R.id.textView1); 
     txt.setText(buffer.toString()); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

privated void Login2() 
{   
    HttpURLConnection connection; 
    OutputStreamWriter request = null; 

     URL url = null;   
     String parameters = "username=" + user.getText().toString() + "&password=" + pass.getText().toString(); 

     try 
     { 
      url = new URL("https://xxxxx.xxxxxx.xxx/index.php?pModule=bG9naW4=&pSub=bG9naW4=&pAct=cHJvY2Nlc3M="); 
      connection = (HttpURLConnection) url.openConnection(); 
      connection.setDoOutput(true); 
      connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
      connection.addRequestProperty("Content-Length", Integer.toString(parameters.length())); 
      connection.setRequestMethod("POST");  

      request = new OutputStreamWriter(connection.getOutputStream()); 
      request.write(parameters); 
      request.flush(); 
      request.close();    
      String line = "";    
      InputStreamReader isr = new InputStreamReader(connection.getInputStream()); 
      BufferedReader reader = new BufferedReader(isr); 
      StringBuilder sb = new StringBuilder(); 
      while ((line = reader.readLine()) != null) 
      { 
       sb.append(line + "\n"); 
      }   
      TextView txt = (TextView) findViewById(R.id.textView1); 
      txt.setText(sb.toString());   
      isr.close(); 
      reader.close(); 

     } 
     catch(IOException e) 
     { 
      // Error 
     } 
} 

知っていますか?

ありがとうございました。 私の悪い英語のために申し訳ありません。

答えて

0

は、サーバーが符号化された方法に応じて、それがうまくいくかもしれない、GETとしてクエリを送信してください:

https://xxxxx.xxxxxx.xxx/index.php?pModule=bG9naW4=&username=USERNAME&password=PASSWORD&pSub=bG9naW4=&pAct=cHJvY2Nlc3M= 

あなたがでログオンしたいものは何でも資格情報を使用してUSERNAMEPASSWORDを交換してください。

+0

私はそれを試みましたが、何も答えませんでした。 Webブラウザで手動で試してみると、ユーザー名とパスワードを入力する必要があると言われました。だから、私はサイトがURLパラメータを介してユーザー名とパスワードを渡すのではなく、POSTメソッドを経由していると思います。だから、上記のコードはうまくいくはずです。私はPOSTメソッドを介して渡すために別の引数が必要だと思うが、私は何がわからない。 – Lowen

+0

はい、GETを受信し、POSTを受信したときに実際にログインしようとすると、サーバー側コードがおそらくログインページを表示しています。それは普通のパターンだ – Guillaume

+0

私はそれがhttpsに起因すると思うが、私はhttps // account.google.comにアクセスしようとし、私はPOSTメソッドを使用することができないと答えた。それともクッキーが提供されていないことが原因ですか? – Lowen

関連する問題