Use HttpClient to simulate the browser login site, and then you can do things, such as publishing information, etc.
First step : Get the actual post URL (without considering the complexity of the case)
1, need to use the Httpfox plug-in to Firefox, Httpfox clear a bit, and then start to capture
2, switch back to the page login page, start to enter their own account password login, log in successfully after the cut back to Httpfox stop, see the recent Post method contains the post data data, and this post method URL address,
3. This gives the data parameters (Parameter) and values (value)that need to be post when impersonating the login, and the URL of the actual post
Step two , use httpclient to log in
1, the simple core code is as follows
1Closeablehttpclient httpclient =Httpclients.createdefault ();2list<namevaluepair> PostData =NewArraylist<namevaluepair>();3 //there may be multiple parameters here4Postdata.add (NewBasicnamevaluepair ("username", "username"));5Postdata.add (NewBasicnamevaluepair ("Password", "password"));6 //The URL is the actual post address, using Httpfox to get7HttpPost HttpPost =NewHttpPost (URL);9 Try { OneHttppost.setentity (NewUrlencodedformentity (PostData, "GBK")); AResponse =Httpclient.execute (httppost); the}Catch(IOException e) { -}finally { - Closeio (response); -}
The Java language uses HttpClient to impersonate a browser login