package com.li.utli;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;/**
 * 下载验证码的
 * @author Legend、
 *
 */
public class VerificationcCode {
   
//发送post请求获取验证码
public static void showVerificationcCode(String url,String fileUrl) throws ClientProtocolException, IOException{
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
InputStream in= entity.getContent();
int temp = 0;
File file = new File(fileUrl);
FileOutputStream out = new FileOutputStream(file);
while((temp=in.read())!=-1){
 out.write(temp);
}
in.close();
out.close();
} //发送get请求获取验证码
public static String showGetVerificationcCode(String url,Map<String ,String> header, String fileUrl) throws ClientProtocolException, IOException {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
if(null!=header&&header.size()>0){
get.setHeaders(SendRequest.assemblyHeader(header));
}
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream in= entity.getContent();
int temp = 0;
File file = new File(fileUrl);
FileOutputStream out = new FileOutputStream(file);
while((temp=in.read())!=-1){
 out.write(temp);
}
in.close();
out.close();
return SendRequest.assemblyCookie(client.getCookieStore().getCookies());
}
}最后的主方法:package com.li.main;/**
 *  主方法
 * @author Legend、
 *
 */
public class BaiduMain {
public static void main(String[] args) throws Exception {
        
//验证账号并获取cookie
String cookie  =  BaiduTieBaNDWS.testAccount("", "");
//发帖
String info = BaiduTieBaNDWS.reply("这个贴狠牛B啊!!", "http://tieba.baidu.com/p/1193625840", cookie);
//打印返回信心
System.out.println(info);
}
}除了BaiduTieBaNDWS这个类之外,其他的类都可以直接重用。。除了百度贴吧、我们还可以做百度知道,各大论坛的回复,或者可以刷网上投票啊,我想一些网购的秒杀也是一样的,就是发一个请求带上一些必要参数而已小菜第一次发这种技术贴,写的不好之处请大家海涵!

解决方案 »

  1.   

    注释做的不错!
    对于httpClient来说,还是不错的!
      

  2.   

    注释写的非常细,另外,以CSDN为例来做是不会删贴的。     CSDN 本身也提供了API供调用的。推荐了
      

  3.   

    httpClient4和3的区别很大,改动很大
      

  4.   

    汗啊。。上次也是用这种方法,,做了个csdn资源分的刷分器。。结果2分钟之内就被删帖了
      

  5.   


    哈哈,这个删除很正常。 你就做个CSDN发贴,回贴工具,很正常的。。
      

  6.   

    好东西,改天我发个HttpURLConnection的。
      

  7.   

    Obtain luggage michael kors hamilton bag
    Feet Away from My own DashboardMy partner and i attained Freedy Johnston when your dog seemed to be this best take action about the Silos Chook tour. He opened for many people in a number of appointments in the Northeast, advertising her very first file, Your Difficulty Tree. He / she had been any wiry, clumsy chap from Kansas. Their song appeared to be a new blend involving Land, Indie plus Redneck. Greater than performing, he or she experienced a new mad bin vocal type of screeching by means of his music. He or she consciously tamed this specific vocal fashion by the time period Harmful Reputation ended up being noted. In my opinion this particular “improvement” has been some sort of michael kors hamilton handbag sale
    mistake but not adviser in the Freedy My spouse and i the moment recognized. “Get feet away from my dashboard. Exactly what on earth do you consider the particular damn thing’s pertaining to? At least make an attempt to glimpse pretty. For dinner we’re goin’ in Tucumcari, ” he or she sang for theluggage michael kors hamilton bag
     Iron bars Moose around Northampton, MA. The actual blend which was Freedy Johnston was brilliant. I was right away used by means of your ex.Your Silos’ office manager, Recognise Zoltak known Freedy’s talent and also pounced. Within a short time that they possessed a doing work set up and have been already planning the latest documenting (Would you Soar). Graham Maby cheap michael kors hamilton bag
    michael michael kors hamilton
    along with Post have been this bass person and also drummer while in the Silos. Then it was a no-brainer pertaining to Freedy to engage us all to learn with his periods. While in the meantime there seems to be hard work for being completed. The revolutionary songs had to possibly be formed plus pointed. Rehearsals ended up in a very stiflingly sizzling studio upon other Block throughout Hoboken. Inside the period prior to the particular periods, just about all Freedy may deliver us all seemed to be this assurance with participating in good quality tracks. Otherwise ıt had been delinquent rehearsals, items schlepping along with membership gigs. Some sort of combination among a new play class and an internship. There are some good gigs cracking open to get more proven functions just like the Connells and also Pere Ubu, nevertheless these were vemk hamilton tote
    ry few and also significantly involving. With Freedy along with Jimmy Lee about various guitars, the ones you have definitely about percussion, plus Television’s His father Smith with striped bass, we all forged in advance enjoying club gigs and also healthy diet this tracks for the upcoming times regarding Would you Soar. mk hamilton large tote black
    mk Hamilton tote luggage
    luggage mk hamilton tote
    mk large Hamilton tote
    michael kors hamilton satchel
    michael kors hamilton satchel black
    black mk hamilton satchel
    michael kors hamilton satchel sale
    kors hamilton luggage
    michael kors large hamilton satchel luggage
    Michael Michael kors Hamilton large tote
      

  8.   

    楼主
    返回
    "no":2101,"error":"","data":{"fid":2829320,"fname":"\u541e\u566c\u661f\u7a7a","is_login":0}}
    什么意思没回成功
      

  9.   

    我给原公司开发了一个基于httpclient4开发的webqq客户端。其实它挺好用的,支持长连接和短链接。WEBQQ就需要长链接。
      

  10.   

    你再看看怎么改下 哈哈
    我对这个HttpClient一窍不通 ,看了半天没看懂 可能对请求需要的一些信息不了解吧
    拿下来运行下返回错误信息
    楼主加油改下
      

  11.   

    当然输入了 我调试了能正确登入 就是最后回帖失败了//准备好一切,回帖
            Result res = SendRequest.sendPost("http://tieba.baidu.com/f/commit/post/add", headers, parameters, "utf-8");
            
            //回帖之后百度会返回一段json,说明是否回帖成功
            return EntityUtils.toString(res.getHttpEntity(),"utf-8");