Refresh 51cto or CSDN traffic

Source: Internet
Author: User

Package Xian;


Import Java.util.concurrent.ExecutorService;

Import java.util.concurrent.Executors;

Import org.apache.commons.httpclient.HttpClient;

Import Org.apache.commons.httpclient.HttpStatus;

Import Org.apache.commons.httpclient.methods.GetMethod;


public class Refreshblog {


private static volatile int number = 0;

Private static final String URL = "http://hackerxian.blog.51cto.com/9240575/1615425";

Private static final String URL = "http://blog.csdn.net/jiazhipeng12/article/details/43731675";

Simply use a thread pool

private static Executorservice es = Executors.newfixedthreadpool (30);

public static void Main (string[] args) {

Simply use a thread pool

Executorservice es = Executors.newfixedthreadpool (30);

The number of threads should be based on your own network. My home is 10M net so 20 is basically the upper limit.

for (int i=0;i<1;i++) {

Runnable r = new Runnable () {

public void Run () {

Refreshblog ();

}

};

Es.submit (R);

//refreshblog ();

}

}

/**

* Refreshblog This method is the corresponding request

* @author Heinz_ho

* @return void

*/

public static void Refreshblog () {

HttpClient httpclient=new HttpClient ();

GetMethod GetMethod = new GetMethod (URL);

Csdn

Getmethod.setrequestheader ("User-agent", "mozilla/5.0" (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/39.0.2171.99 safari/537.36 lbbrowser ");

51cto

Getmethod.setrequestheader ("User-agent", "mozilla/5.0" (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/40.0.2214.115 safari/537.36 lbbrowser ");

Actually, I don't know much about it here. I just know about the cookie generation strategy, but because CSDN will have a good sense of what the cookie is. Must be added. Browser_compatibility

Getmethod.getparams (). Setcookiepolicy (Org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY) ;

while (true) {

try {

This sentence can cause blocking because you want the network to initiate the request.

int statusCode = Httpclient.executemethod (GetMethod);

if (statusCode! = HTTPSTATUS.SC_OK) {

System.out.print ("failure:" + getmethod.getstatusline ());

Thread thread = Thread.CurrentThread ();

Thread.Sleep (1500);//pause for 1.5 seconds until the program resumes execution

Return

}

SYSTEM.OUT.PRINTLN ("You have refreshed:" +number++);

} catch (Exception e) {

System.out.print ("Please check the network address!") ");

} finally {

Getmethod.releaseconnection ();

}

}

}

/* public static void Go (GetMethod getmethod) {

HttpClient httpclient=new HttpClient ();

Laziness uses a dead loop.

while (true) {

try {

This sentence can cause blocking because you want the network to initiate the request.

int statusCode = Httpclient.executemethod (GetMethod);

if (statusCode! = HTTPSTATUS.SC_OK) {

System.out.print ("failure:" + getmethod.getstatusline ());

Thread thread = Thread.CurrentThread ();

Thread.Sleep (1500);//pause for 1.5 seconds until the program resumes execution

}

SYSTEM.OUT.PRINTLN ("You have refreshed:" +number++);

} catch (Exception e) {

System.out.print ("Please check the network address!") ");

} finally {

Getmethod.releaseconnection ();

}

}

}*/

}




Several jar packages required: http://download.csdn.net/detail/jiazhipeng12/8458661

This article is from the "Jia Xiaoxian" blog, make sure to keep this source http://hackerxian.blog.51cto.com/9240575/1615425

Refresh 51cto or CSDN traffic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.