如何通过抓包工具fiddler获取java程序的http请求
1个回答
2017-08-07 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
抓包工具fidder是一个很轻巧的可以获取浏览器,程序的http,https请求的软件。
百科地址:http://baike.baidu.com/view/868685.htm
官网地址:http://fiddler2.com/
firefox的fidder插件
而Java程序需要设置proxy才能生效:
[java] view plain copy
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);
详细代码请下载。
[java] view plain copy
package com.zuidaima.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;
/**
*@author www.zuidaima.com
**/
public class Http302Redirect {
public static void main(String[] args) {
try {
String url = "http://www.zuidaima.com/";
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://javaniu.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("\r\n");
line = reader.readLine();
}
reader.close();
conn.disconnect();
System.out.println(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
}
百科地址:http://baike.baidu.com/view/868685.htm
官网地址:http://fiddler2.com/
firefox的fidder插件
而Java程序需要设置proxy才能生效:
[java] view plain copy
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);
详细代码请下载。
[java] view plain copy
package com.zuidaima.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;
/**
*@author www.zuidaima.com
**/
public class Http302Redirect {
public static void main(String[] args) {
try {
String url = "http://www.zuidaima.com/";
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://javaniu.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("\r\n");
line = reader.readLine();
}
reader.close();
conn.disconnect();
System.out.println(buffer);
} catch (Exception e) {
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询