java抓取有验证的页面内容
2016-01-26 17:57
447 查看
package zz.test.ssm.controller; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.servlet.http.HttpServletRequest; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping(value = "/mq") public class MqQueueController { @RequestMapping(value = "queue", method = RequestMethod.GET) @ResponseBody public String getMqQueue(HttpServletRequest request) throws HttpException, IOException { String response = ""; String queueName = request.getParameter("queue"); String username = "user"; String password = "pass"; String url = "http://192.168.50.2:1002/api/queues/%2Femsfeedback/"+queueName; HttpClient client = new HttpClient(); client.getState().setCredentials( new AuthScope("192.168.50.2", 1002), new UsernamePasswordCredentials(username, password)); GetMethod get = new GetMethod( url ); get.setDoAuthentication( true ); int status = client.executeMethod( get ); response = get.getResponseBodyAsString(); System.out.println(status+ "\n" + get.getResponseBodyAsString()); get.releaseConnection(); return response; } }
参考:
http://www.blogjava.net/jelver/articles/162339.html
/article/5031076.html
相关文章推荐
- spring有办法在getBean的时候传入构造函数的参数吗?
- 使用java HBase API查询 小bug记录
- myeclipse一直bulid workspace 的解决
- Spring Boot工程支持HTTP和HTTPS,HTTP重定向HTTPS
- 使用Spring管理Bean
- 什么叫依赖(spring)
- The Java™ Tutorials — Generics :Bounded Type Parameters 受限的类型参数
- Java提高篇(三六)-----java集合细节(二):asList的缺陷
- 对Java Serializable(序列化)的理解和总结
- Eclipse的Debug介绍与技巧
- spring的面向切面实现的两种方式
- Java提高篇(三五)-----Java集合细节(一):请为集合指定初始容量
- eclipse 下找不到或无法加载主类的解决办法
- Java——枚举类详解
- myEclipse 控制台右边的按钮作用
- System.setErr()
- 基本java打洞通信实现p2p
- Java提高篇(三四)-----fail-fast机制
- spring-关系数据库操作对象化
- Java类加载过程分析