类的主要方法见 http://download.csdn.net/detail/czw698/8075039 下载该文档
在spring 中的配置
<bean id="boceHttpClient" class="com.niux.matador.util.HttpClientUtil">
<constructor-arg index="0" value="http://sh.kh8.cc" />
<constructor-arg index="1" value="15000" />
<constructor-arg index="2" value="30000" />
</bean>
使用方式:
@Resource
private HttpClientUtil boceHttpClient;
@RequestMapping("/index")
public String index(HttpServletRequest request){
byte[] bt = boceHttpClient.doGetReByte("ctl=inc&act=validcode"); // 一般获取的都是String 因为这里要取的验证码图片,所以要获取字节,然后再转成图片
try {
FileImageOutputStream imageOutput = new FileImageOutputStream(new File("D:\\a.png"));// 生成图片
imageOutput.write(bt, 0, bt.length);
imageOutput.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// request.setAttribute("codurl", "http://sh.kh8.cc/?ctl=inc&act=validcode");
return "merchantBlack/index";
}