码迷,mamicode.com
首页 > 编程语言 > 详细

如何通过抓包工具fiddler获取java程序的http请求

时间:2015-02-14 11:03:31      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:java   抓包工具   fiddler   程序   http   

原文:如何通过抓包工具fiddler获取java程序的http请求

源代码下载地址:http://www.zuidaima.com/share/1550463683824640.htm

抓包工具fidder是一个很轻巧的可以获取浏览器,程序的http,https请求的软件。

百科地址:http://baike.baidu.com/view/868685.htm

官网地址:http://fiddler2.com/

firefox的fidder插件

技术分享

而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.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();
		}
	}

}


如何通过抓包工具fiddler获取java程序的http请求

标签:java   抓包工具   fiddler   程序   http   

原文地址:http://blog.csdn.net/springmvc_springdata/article/details/43816329

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!