关于HttpClient请求https网页??? 关于HttpClient请求https网页,需要做什么处理么?还是就和处理http一样直接照通常方法请求? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;public class UrlConnect { public static void main(String[] args) { new NetWin(); }}class NetWin extends JFrame implements ActionListener, Runnable { JButton button; URL url; JTextField text; JEditorPane area; byte b[] = new byte[118]; Thread thread; String URL = "http://www.baidu.com/s?wd="; String fin; private Color white; NetWin() { text = new JTextField(20); area = new JEditorPane(); button = new JButton("查询"); button.addActionListener(this); thread = new Thread(this); JPanel p = new JPanel(); p.add(new JLabel("连接百度,请输入关键字:")); p.add(text); p.add(button); p.setBackground(white); add(area, BorderLayout.CENTER); add(p, BorderLayout.NORTH); setBounds(60, 60, 600, 400); setVisible(true); validate(); } public void actionPerformed(ActionEvent e) { if (!(thread.isAlive())) thread = new Thread(this); try { thread.start(); } catch (Exception ee) { text.setText("我正在读取" + url); } } public void run() { try { int n = -1; area.setText(null); area.setVisible(true); fin = text.getText(); URL += fin; url = new URL(URL); InputStream in = url.openStream(); while ((n = in.read(b)) != -1) { String s = new String(b, 0, n); area.setPage(URL); } } catch (MalformedURLException e1) { text.setText("" + e1); return; } catch (IOException e1) { text.setText("" + e1); return; } }} 应该是一样的,https是通过证书加密的,这是服务器端的事,和你请求应该没有什么关系。请求URL直接从http://变成https应该可以。具体我倒是没有试验过。 请参考 http://yjhexy.javaeye.com/blog/576964 这篇文章,我以前按照这篇文章已经成功实现了使用httpclient访问需要pfx文件的https网站。不过里面有一句话是错的,它里面写:“首先把a.pfx导入到IE。然后用IE的Internet选项--》内容--》证书--》导出成不带私钥的cer格式就搞定了”,其实这样导出的cer文件是错的,应该这么做:通过浏览器访问时第二下弹出的“安全警报”—>“查看证书”—>“详细信息”—>“复制到文件”……导出cer格式的文件,这个cer文件才是正确的。 装了JAD之后,Eclipse的配置问题 要不重复的随机数 覆盖方法时返回类型不一样会出现怎样的情况 Applet 急!请问如何从JScrollPane中如何取出JTable? swing ,Frame 获取标题栏上最大化和关闭按钮 和 static main()的问题 properties文件的中文乱码问题 我的数据库问题!盼望在线的各位帮帮! 这是为什么? 请问字符串‘\12’代表什么啊? 线程的几个问题 如何用Graphics2D实现以下的图片局部旋转效果?
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;public class UrlConnect { public static void main(String[] args) {
new NetWin();
}}class NetWin extends JFrame implements ActionListener, Runnable {
JButton button;
URL url;
JTextField text;
JEditorPane area;
byte b[] = new byte[118];
Thread thread;
String URL = "http://www.baidu.com/s?wd=";
String fin; private Color white; NetWin() {
text = new JTextField(20);
area = new JEditorPane();
button = new JButton("查询");
button.addActionListener(this);
thread = new Thread(this);
JPanel p = new JPanel();
p.add(new JLabel("连接百度,请输入关键字:"));
p.add(text);
p.add(button);
p.setBackground(white);
add(area, BorderLayout.CENTER);
add(p, BorderLayout.NORTH);
setBounds(60, 60, 600, 400);
setVisible(true);
validate();
} public void actionPerformed(ActionEvent e) {
if (!(thread.isAlive()))
thread = new Thread(this);
try {
thread.start();
} catch (Exception ee) {
text.setText("我正在读取" + url);
}
} public void run() {
try {
int n = -1;
area.setText(null);
area.setVisible(true);
fin = text.getText();
URL += fin;
url = new URL(URL);
InputStream in = url.openStream();
while ((n = in.read(b)) != -1) {
String s = new String(b, 0, n);
area.setPage(URL);
}
} catch (MalformedURLException e1) {
text.setText("" + e1);
return;
} catch (IOException e1) {
text.setText("" + e1);
return;
}
}}
请求URL直接从http://变成https应该可以。具体我倒是没有试验过。
不过里面有一句话是错的,它里面写:“首先把a.pfx导入到IE。然后用IE的Internet选项--》内容--》证书--》导出成不带私钥的cer格式就搞定了”,其实这样导出的cer文件是错的,应该这么做:通过浏览器访问时第二下弹出的“安全警报”—>“查看证书”—>“详细信息”—>“复制到文件”……导出cer格式的文件,这个cer文件才是正确的。