Push data in java and submit data in proxy post
On the Internet .. Leave backup.
[Java]
Import org. apache. commons. httpclient .*;
Import org. apache. commons. httpclient. methods. GetMethod;
Import org. apache. commons. httpclient. methods. PostMethod;
Import org. apache. commons. httpclient. params. HttpClientParams;
Import org. apache. commons. httpclient. params. HttpMethodParams;
Import java. awt. image. BufferedImage;
Import java. io. InputStream;
Import javax. imageio. ImageIO;
Public class MyHttpClient {
/***//**
* Method description
*
*
* @ Param title: Message title
* @ Param name: message recipient
* @ Param Content
* @ Param proIP proxy IP
* @ Param port proxy port
* @ Param usePro whether to use a proxy
*/
Public synchronized void doSomeThing (String title, String name, String Content, String proIP, int port,
Boolean usePro ){
// Construct an HttpClient instance
HttpClient httpClient = new HttpClient ();
HttpClientParams clientParams = new HttpClientParams ();
// Hide information related to your request
ClientParams. setParameter ("http. useragent", "Mozilla/4.0 (compatible; FIREFOX 9.0; ibm aix 5 )");
// HttpClient. getHttpConnectionManager (). getParams (). setSoTimeout (30*1000 );
ClientParams. setHttpElementCharset ("GBK ");
HttpState httpState = new HttpState ();
HttpClient. setParams (clientParams );
HttpClient. getParams (),. setParameter (HttpClientParams. HTTP_CONTENT_CHARSET, "GBK ");
HttpClient. setState (httpState );
ClientParams. setVersion (HttpVersion. HTTP_1_1 );
// HttpClient. getHostConfiguration (). setProxy ("148.233.15 9.58", 3128 );
If (usePro) // use a proxy
...{
HttpClient. getHostConfiguration (). setProxy (proIP, port );
}
// Create an instance of the GET Method
GetMethod getMethod = new GetMethod ("http://www.XXXcom/Guestbook/imgchk/validatecode.asp ");
// Use the default recovery policy provided by the system
GetMethod. getParams (). setParameter (HttpMethodParams. RETRY_HANDLER, new DefaultHttpMethodRetryHandler ());
Try ...{
// Execute getMethod
Int statusCode = httpClient.exe cuteMethod (getMethod );
// System. out. println (statusCode );
If (statusCode! = HttpStatus. SC _ OK ){
System. err. println ("Method failed:" + getMethod. getStatusLine ());
} // Read content
InputStream inStream = getMethod. getResponseBodyAsStream ();
// Process content
// System. out. println (new String (responseBody ));
BufferedImage iag = ImageIO. read (inStream );
ImgIdent imgIdent = new ImgIdent (iag );
// ImgIdent. saveJPEG (iag, "C:/ddd.jpg ");
String validate = imgIdent. getValidatecode (4 );
System. out. println (validate );
PostMethod method = new PostMethod ("http://www.XXX.com/Guestbook/add_msg.asp ");
String connect = Content;
String Title = title;
Method. setParameter ("subject", Title );
Method. setParameter ("g_name", name );
Method. setParameter ("companyname ","");
Method. setParameter ("mail ","");
Method. setParameter ("homepageurl", "http ://");
Method. setParameter ("pic", "p5.gif ");
Method. setParameter ("validatecode", validate );
Method. setParameter ("content", connect );
// If (todo ){
Int code = httpClient.exe cuteMethod (method );
// String Stringresponse = new String (method. getResponseBodyAsString (). getBytes ("8859_1 "));
// Print the returned information
// System. out. println (Stringresponse );
//}
Method. releaseConnection ();
// System. out. println (iag. getHeight ());
// System. out. println (iag. getWidth ());
/// Background color
// IntBgColor = iag. getRGB (38, 0 );
// System. out. println ("intBgColor =" + intBgColor );
//
//
// IntBgColor = iag. getRGB (0, 0 );
// System. out. println ("intBgColor =" + intBgColor );
} Catch (Exception e ){
// Network exception
E. printStackTrace ();
} Finally {}
// Release the connection getMethod. releaseConnection ();}
GetMethod. releaseConnection ();
}
}