http://bbs.csdn.net/topics/390426978
public static String Readcheckimage (hashmap<string, string> requestmap) {
String url = requestmap.get ("url");
if (Requestmap.get ("params") = null) {
URL + = "?" + requestmap.get ("params");
}
InputStream in = null;
try {
System.out.println ("get>>>" + URL);
URL serverurl = new URL (URL);
HttpURLConnection conn = (httpurlconnection) serverurl.openconnection ();
Conn.setrequestmethod ("get");//"POST", "get"
Conn.addrequestproperty ("Cookie", Requestmap.get ("Cookie"));
Conn.addrequestproperty ("Accept-charset", "UTF-8;"); /GB2312,
Conn.addrequestproperty ("User-agent",
"Mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.2.8) firefox/3.6.8 ");
Conn.connect ();
Determine if the request was successful
if ((httpurlconnection) conn). Getresponsecode () = = 200) {
Get all response header fields
map<string, list<string>> map = Conn.getheaderfields ();
Iterate through all the response header fields
For (String Key:map.keySet ()) {
SYSTEM.OUT.PRINTLN (key + "--->" + map.get (key));
}
The returned cookie
String cookie = null;
if (Conn.getheaderfields (). Get ("Set-cookie")! = null) {
For (String S:conn.getheaderfields (). Get ("Set-cookie")) {
Cookie + = s;
}
}
Requestmap.put ("Cookie", Requestmap.get ("cookie") + cookie);
in = Conn.getinputstream ();
BufferedImage bi = imageio.read (in);
File F = new file ("Check_img.jpg");
Imageio.write (BI, "JPG", f);
return F.getabsolutepath ();
} else {
System.out.println ("Download code image failed!") ");
}
} catch (Exception e) {
E.printstacktrace ();
}//using the finally block to close the input stream
finally {
try {
if (in = null) {
In.close ();
}
} catch (Exception E2) {
E2.printstacktrace ();
}
}
return null;
}
How to obtain a Web Captcha picture and save it to a local (Java implementation) [problem points: 40 points, knot man Lanxuezaipiao]