package com.gomt.httpclient;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLDocument;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class AutoTest {
static final String LOGON_SITE = "192.168.0.93";
static final int LOGON_PORT = 7001;
public AutoTest() {
}
/**
* @param args
*/
public static void main(String[] args) {
HttpClientFrame f = new HttpClientFrame();
f.setTitle("HttpClient测试");
f.setSize(700, 500);
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
f.setVisible(true);
}
public static class HttpClientFrame extends JFrame {
private static final long serialVersionUID = 3348783285573305436L;
private JComboBox cmbURL;
private JComboBox runcount;
private JTextField cmbPort;
private JTextArea taTextResponse;
private JEditorPane htmlPane;
private HttpClient client;
String[] userArr = new String[]{"admin", "tianyy", "jiangzy", "caoxd", "changam", "chejh", "chench", "chengh", "chenhr", "guzm", "hesb", "hep", "laijw"};
String[] passArr = new String[]{"admin", "tian", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"};
long begin = 0;
public HttpClientFrame() {
begin = System.currentTimeMillis();
System.out.println("start : " + begin);
//HttpClient
client = new HttpClient(new MultiThreadedHttpConnectionManager());
//client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
client.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
JPanel panInput = new JPanel(new FlowLayout());
String[] aURLs = {
"192.168.0.9",
"192.168.0.10",
"192.168.0.93"//,
//"http://www.anybrowser.org/",
//"http://jakarta.apache.org/",
//"http://www.w3.org/"
};
final JButton btnGET = new JButton("测试");
btnGET.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String url = (String) cmbURL.getSelectedItem();
if (url != null && url.length() > 0) {
//loadPage(url);
int runtimes = 1;
int port = 80;
try {
runtimes = Integer.parseInt((String)runcount.getSelectedItem());
} catch(Exception eee) {
runtimes = 1;
}
try {
port = Integer.parseInt(cmbPort.getText());
} catch(Exception ee) {
port = 80;
}
java.util.Random rm = new java.util.Random();
for (int i = 0; i < runtimes; i++) {
int rmi = rm.nextInt();
int arryp = Math.abs(rmi % 13);
System.out.println("arryp = " + arryp);
loadPage(url, i+1, begin, userArr[arryp], passArr[arryp], port);
// PostMethod post = new PostMethod("http://" + url + ":" + LOGON_PORT + "/szsf/loginaction.action");
// NameValuePair username = new NameValuePair("user", userArr[arryp]);
// NameValuePair password = new NameValuePair("pwd", passArr[arryp]);
// NameValuePair method = new NameValuePair("method", "b");
// post.setRequestBody(new NameValuePair[]{username, password, method});
//get.setFollowRedirects(true);
}
}
}
}
);
cmbURL = new JComboBox(aURLs);
cmbURL.setToolTipText("输入一个地址!");
cmbURL.setEditable(true);
cmbURL.setSelectedIndex(0);
cmbPort = new JTextField();
cmbPort.setToolTipText("请输入端口号!");
cmbPort.setEditable(true);
cmbPort.setText("7001");
JLabel lblURL = new JLabel("地址:");
runcount = new JComboBox(new String[]{"1","10","100","1000"});
runcount.setToolTipText("运行次数");
runcount.setEditable(true);
runcount.setSelectedIndex(0);
panInput.add(lblURL);
panInput.add(cmbURL);
panInput.add(cmbPort);
panInput.add(btnGET);
panInput.add(runcount);
panInput.add(new JLabel("次"));
taTextResponse = new JTextArea();
taTextResponse.setEditable(false);
taTextResponse.setCaretPosition(0);
htmlPane = new JEditorPane();
htmlPane.setContentType("text/html;charset=UTF-8");
htmlPane.setEditable(false);
JSplitPane splitResponsePane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(taTextResponse),
new JScrollPane(htmlPane)
);
splitResponsePane.setOneTouchExpandable(false);
splitResponsePane.setDividerLocation(350);
// it would be better to set resizeWeight, but this method does
// not exist in JRE 1.2.2
// splitResponsePane.setResizeWeight(0.5);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(panInput, BorderLayout.NORTH);
this.getContentPane().add(splitResponsePane, BorderLayout.CENTER);
}
/**
* Sets the HTML content to be displayed.
*
* @param content an HTML document
* @throws UnsupportedEncodingException
*/
private void setDocumentContent(String content, InputStream in) throws UnsupportedEncodingException {
HTMLDocument doc = new HTMLDocument();
try {
doc.remove(0, doc.getLength());
} catch (BadLocationException e) {
e.printStackTrace();
}
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
try {
htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
} catch (IOException e) {
e.printStackTrace();
}
htmlPane.set
json.jar
5星 · 超过95%的资源 需积分: 10 109 浏览量
2008-04-04
22:42:15
上传
评论 5
收藏 2.55MB RAR 举报
a130569
- 粉丝: 0
- 资源: 1
最新资源
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
- 基于matlab+DWT的图像水印项目,数字水印+源代码+文档说明+图片+报告pdf
- (优秀毕业设计)基于python实现的数字图像可视化水印系统的设计与实现,多种数字算法实现+源代码+文档说明+理论演示pdf
- 基于DWT-DCT-SVD和deflate压缩的数字水印方法python源码+Gui界面+演示视频(高分毕业设计)
- 基于matlab实现DWT、DCT、SVD算法数字图像水印可视化系统+GUI界面+文档说明+详细注释(高分毕业设计)
- NCIAE-Data-Structure大一大二笔记
- 学习wireshark笔记
- digital-image-数据可视化笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页