概述
抓包工具fidder是一个很轻巧的可以获取浏览器,程序的http,https请求的软件。
百科地址:http://baike.baidu.com/view/868685.htm
官网地址:http://fiddler2.com
而java程序需要设置proxy才能生效:
Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1", 8888));
URL serverUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(proxy);
详细代码:
package com.http;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
public class Http302Redirect {
public static void main(String[] args) {
try {
String url = "http://weibo.com/1253711052";
System.out.println("访问地址:" + url);
Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,
new InetSocketAddress("127.0.0.1", 8888));
URL serverUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) serverUrl
.openConnection(proxy);
conn.setRequestMethod("GET");
conn.addRequestProperty("Accept-Charset", "UTF-8;");
conn.addRequestProperty("User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Firefox/3.6.8");
conn.addRequestProperty("Referer", "http://weibo.com");
conn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
StringBuffer buffer = new StringBuffer();
String line = reader.readLine();
while (line != null) {
buffer.append(line).append("rn");
line = reader.readLine();
}
reader.close();
conn.disconnect();
System.out.println(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
最后
以上就是贪玩乌龟为你收集整理的java pc端软件抓包,如何通过抓包工具fiddler获取java程序的http请求的全部内容,希望文章能够帮你解决java pc端软件抓包,如何通过抓包工具fiddler获取java程序的http请求所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复