Tuesday, February 18, 2014

Httpclient have used successfully with the help of landing facie verification code has been successful not fast sick


We wanted to do a school with httpclient educational system agents landing APP, school connection is http://jwgl2.jmu.edu.cn/Common/Login.aspx, by capturing, finding the target Url To login information and POST Url landing page is the same, and access to the relevant data to pass, first paste the code
Before this last POST is also to get a verification code, as to ensure the effectiveness of the verification code, I was doing before calling login () method first performs a post, and save the cookie POST after, then with This cookie to access the verification code pages. Write a handle inside
 public void handleMessage (Message msg) {
if (result! = null) {
Intent intent = getIntent (); / / Get Intent object
Bundle bundle = new Bundle (); / / instantiate transmitted packets


String target = "http://jwgl2.jmu.edu.cn/common/login.aspx"; / / destination address to submit
HttpPost httpRequest_1 = new HttpPost (target); / / create HttpPost object
/ / Save the parameters to be passed to the List collection
List params = new ArrayList ();
params.add (new BasicNameValuePair ("TxtUserName", username)); / / username
params.add (new BasicNameValuePair ("TxtPassword", pwd)); / / password
params.add (new BasicNameValuePair ("BtnLoginImage.x", "1")) ;/ / 0 for landing when the two press Enter
params.add (new BasicNameValuePair ("BtnLoginImage.y", "1"));


try {
httpRequest_1.setEntity (new UrlEncodedFormEntity (params, HTTP.UTF_8)); / / set encoding
HttpResponse httpResponse1 = MainActivity.httpclient
. Execute (httpRequest_1); / / execute HttpClient request
if (httpResponse1.getStatusLine (). getStatusCode () == 200) {
/ / If the request is successful


. MainActivity.cookies = ((AbstractHttpClient) MainActivity.httpclient) getCookieStore () getCookies ();.

System.out.println ("first click to get verification code when the cookie >>" + MainActivity.cookies.get (0) getValue ().);
}
/ * Here is to get the verification code and display * /
in layoutcheckicon = (ImageView) findViewById (R.id.code);
byte [] data = CheckCode.getImageViewArray ();
Bitmap bitmap = BitmapFactory.decodeByteArray (data, 0, data.length);
checkicon.setImageBitmap (bitmap);

} Catch (UnsupportedEncodingException e1) {
e1.printStackTrace (); / / output error message
} Catch (ClientProtocolException e) {
e.printStackTrace (); / / output error message
} Catch (IOException e) {
e.printStackTrace (); / / output error message
} Finally {
httpRequest_1.abort ();
}
}
super.handleMessage (msg);
}

Finally, attach the acquisition method validation code,
 public static byte [] getImageViewArray () {
byte [] data = null;
InputStream inputStream = null;
/ / Do not need to close the output stream is written directly to memory
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();

HttpClient httpclient = new DefaultHttpClient ();
HttpGet httpRequest = new HttpGet (URL_PATH);
HttpResponse httpResponse;
byte [] b_data = new byte [1024];
int len ​​= 0;
try {
System.out.println (MainActivity.cookies.get (0) getValue ().);
httpRequest.setHeader ("Cookie", "ASP.NET_SessionId =" + MainActivity.cookies.get (0) getValue ().);
httpResponse = httpclient.execute (httpRequest);

if (httpResponse.getStatusLine (). getStatusCode () == 200) {
HttpEntity entity = httpResponse.getEntity ();
InputStream is = entity.getContent ();
while ((len = is.read (b_data))! = -1) {

outputStream.write (b_data, 0, len);

}

data = outputStream.toByteArray ();

MainActivity.cookies2 = ((AbstractHttpClient) httpclient) getCookieStore () getCookies ();..
System.out.println ("verification code cookie:" + MainActivity.cookies2);
. / / MainActivity.cookies = ((AbstractHttpClient) MainActivity.httpclient) getCookieStore () getCookies ();.

}
}
catch (ClientProtocolException e) {
e.printStackTrace ();
}
catch (IOException e) {
/ / TODO: handle exception
e.printStackTrace ();
}

return data;
}
verification code when I get there setHeader ("cookie", "ASP.NET_SessionId =" + MainActivity.cookies.get (0) getValue ().); Here MainActiviy.cookies is above the handle POST get inside for the first time, it should also be able to verify the validity of the code of a guarantee, but after the last POST finish school, get a password and verification code, access to the authentication cookie is not successful cookie, and and POST and get a Cookie values ​​obtained after the verification code is different. Leading to the final landing failed, finally, I also have been stuck in here, hope to have developed over httpclient successful landing with a verification code predecessors to give pointers. . It will not solve the problem of too uncomfortable! ! !<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Passing Bangding.

This process is validated or your guess. Suggested capture tool to grab the whole process to log down, then references Post httpclient to do with the Post.
Reply:
mark about
Reply:
Give an account grasped package
Reply:
First parse the source code of the login screen, and then extract the parameters and set the cookie, the name value of the parameter sent to the server, manual landing once the url win after a successful login, direct access to it. Just do this procedure. . . Toss for a long time. . . .
Reply:
references, 4th Floor u012798083 reply:
first parse the login screen of the source code, and then extract the parameters and set the cookie, the name value of the parameter sent to the server , manual landing once the url win after a successful login, direct access to it. Just do this procedure. . . Toss for a long time. . . .
Just to see you stay off the QQ, but to answer your real name, ah, can not add friends ask? Trouble! 869738395
Reply:
reference to the third floor zdd2389 reply:
give account grasped package
can add QQ? Favor. .
Reply:
cited a floor Jia_H reply:
passing Bangding.

This process is validated or your guess. Suggested capture tool to grab the whole process to log down, then references Post httpclient to do with the Post.
I think it should be like this, however, because verify the existence of codes, has been unable to successfully log in, it should be verified code does not match. .

No comments:

Post a Comment