로그인해야하는 페이지에 액세스 할 수있는 안드로이드 앱을 만드는 작업이 있습니다. 해당 사이트에서 사용하는 PHP 코드에 액세스 할 수 없습니다.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 = 내가 로그인 버튼을 클릭하면 갈 방법입니다 것을 볼 : 이 사이트의 HTML 소스입니다. 해당 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=
내가 두 개의 서로 다른 코드를 시도하고 실패했습니다. 이 그 것이다 :
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
}
}
당신이 내 실수 어디 알 수 있습니까?
도움 주셔서 감사합니다. 나쁜 영어로 죄송합니다.
나는 그것을 시도하고 아무 대답도하지 않았다. 웹 브라우저에서 수동으로 시도하면 사용자 이름과 암호를 입력해야한다고 나와 있습니다. 그래서, 나는 사이트가 URL 매개 변수를 통해 사용자 이름과 패스워드를 전달하는 것이 아니라 POST 메소드를 통해 전달할 것이라고 생각한다. 그래서, 위의 코드가 작동해야합니다. POST 메서드를 통해 전달되기 위해서는 또 다른 인수가 필요하다고 생각하지만 무엇을 모르는 것입니다. – Lowen
예 서버 측 코드는 GET을 수신하고 POST를 수신 할 때 실제로 로그인하려고 시도 할 때 로그인 페이지를 렌더링합니다. 일반적인 패턴입니다 – Guillaume
https로 인해 발생했다고 생각하지만 https // account.google.com에 액세스하려고 시도했으며 POST 메서드를 사용할 수 없다고 대답했습니다. 쿠키가 제공되지 않아서 발생 했습니까? – Lowen