当前位置: 技术问答>java相关
我又碰到难题了!!!Apache + Tomcat 怎样配置才能支持ssl? 还有,怎样使java程序能够通过局域网代理访问外网?
来源: 互联网 发布时间:2015-03-28
本文导语: 各位大虾: 我的操作系统是windows2000中文版。IE6.0,jdk1.4.0 beta3版。 apache_1.3.22-win32-x86,ApacheJServ-1.1.2-2,jakarta-tomcat-3.2.4 jsdk20-win32.exe。 问:我还需要那些软件,并且怎样配置,才能使tomcat支持 https协议呢...
各位大虾:
我的操作系统是windows2000中文版。IE6.0,jdk1.4.0 beta3版。
apache_1.3.22-win32-x86,ApacheJServ-1.1.2-2,jakarta-tomcat-3.2.4
jsdk20-win32.exe。
问:我还需要那些软件,并且怎样配置,才能使tomcat支持
https协议呢?
另外:我应该在我的java程序中加入什么代码,才能使我的程序通过
局域网的代理服务器访问外网呢?而且代理服务器是需要校验用户名
密码的那种。(不需要用户名密码校验的代理我已经测试通过。)
主要代码为:
设置代理:
System.getProperties().put( "http.proxySet", "true" );
System.getProperties().put( "http.proxyHost", "proxyHost" );/////////
System.getProperties().put( "http.proxyPort", "proxyPory" );////////
设置用户名密码:(我在程序中加入此代码后不起作用,不知为什么???)
String authString = "UserName:Password";////////
String auth =new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
urlConn.setRequestProperty( "Proxy-Authorization", "Basic "+auth );//"Proxy-Authenticate"
参考程序代码如下:
import java.net.*;
import java.io.*;
public class URLPost extends Object
{
public static void main(String args[])
{
URL destURL;
HttpURLConnection urlConn;
String request;
try{
System.getProperties().put( "http.proxySet", "true" );
System.getProperties().put( "http.proxyHost", "proxyHost" );/////////
System.getProperties().put( "http.proxyPort", "proxyPory" );////////
destURL = new URL("http://www.csdn.net/member/logon.asp");
urlConn = (HttpURLConnection)destURL.openConnection();
String authString = "UserName:Password";////////
String auth =new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
urlConn.setRequestProperty( "Proxy-Authorization", "Basic "+auth );//"Proxy-Authenticate"
request="flytsu&password";
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
urlConn.setAllowUserInteraction(false);
urlConn.setRequestProperty("Content-type","application/x-www-form-urlencoded");
urlConn.setRequestProperty("Content-length", ""+request.length());
DataOutputStream outStream = new DataOutputStream(urlConn.getOutputStream());
outStream.writeBytes(request);
outStream.close();
try{
System.out.println("Print HeaderFile:");
int i=0;
while(urlConn.getHeaderField(i)!=null){
System.out.println(urlConn.getHeaderFieldKey(i)+" "+urlConn.getHeaderField(i));
i++;
}
System.out.println("user-agent= "+urlConn.getHeaderField("User-Agent"));
System.out.println("Proxy-Authorization= "+urlConn.getHeaderField("Proxy02"));
System.out.println("method="+urlConn.getRequestMethod());
System.out.println(""+urlConn.getResponseCode());
DataInputStream inStream = new DataInputStream(urlConn.getInputStream());
int ch;
while ((ch = inStream.read()) >= 0) {
System.out.print((char) ch);
}
inStream.close();
}catch(Exception e){System.out.println("error"+e);}
}catch (Exception e) {
e.printStackTrace();
}
}
}
请各位大虾一定要帮忙解决,分不是问题!
我的操作系统是windows2000中文版。IE6.0,jdk1.4.0 beta3版。
apache_1.3.22-win32-x86,ApacheJServ-1.1.2-2,jakarta-tomcat-3.2.4
jsdk20-win32.exe。
问:我还需要那些软件,并且怎样配置,才能使tomcat支持
https协议呢?
另外:我应该在我的java程序中加入什么代码,才能使我的程序通过
局域网的代理服务器访问外网呢?而且代理服务器是需要校验用户名
密码的那种。(不需要用户名密码校验的代理我已经测试通过。)
主要代码为:
设置代理:
System.getProperties().put( "http.proxySet", "true" );
System.getProperties().put( "http.proxyHost", "proxyHost" );/////////
System.getProperties().put( "http.proxyPort", "proxyPory" );////////
设置用户名密码:(我在程序中加入此代码后不起作用,不知为什么???)
String authString = "UserName:Password";////////
String auth =new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
urlConn.setRequestProperty( "Proxy-Authorization", "Basic "+auth );//"Proxy-Authenticate"
参考程序代码如下:
import java.net.*;
import java.io.*;
public class URLPost extends Object
{
public static void main(String args[])
{
URL destURL;
HttpURLConnection urlConn;
String request;
try{
System.getProperties().put( "http.proxySet", "true" );
System.getProperties().put( "http.proxyHost", "proxyHost" );/////////
System.getProperties().put( "http.proxyPort", "proxyPory" );////////
destURL = new URL("http://www.csdn.net/member/logon.asp");
urlConn = (HttpURLConnection)destURL.openConnection();
String authString = "UserName:Password";////////
String auth =new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
urlConn.setRequestProperty( "Proxy-Authorization", "Basic "+auth );//"Proxy-Authenticate"
request="flytsu&password";
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
urlConn.setAllowUserInteraction(false);
urlConn.setRequestProperty("Content-type","application/x-www-form-urlencoded");
urlConn.setRequestProperty("Content-length", ""+request.length());
DataOutputStream outStream = new DataOutputStream(urlConn.getOutputStream());
outStream.writeBytes(request);
outStream.close();
try{
System.out.println("Print HeaderFile:");
int i=0;
while(urlConn.getHeaderField(i)!=null){
System.out.println(urlConn.getHeaderFieldKey(i)+" "+urlConn.getHeaderField(i));
i++;
}
System.out.println("user-agent= "+urlConn.getHeaderField("User-Agent"));
System.out.println("Proxy-Authorization= "+urlConn.getHeaderField("Proxy02"));
System.out.println("method="+urlConn.getRequestMethod());
System.out.println(""+urlConn.getResponseCode());
DataInputStream inStream = new DataInputStream(urlConn.getInputStream());
int ch;
while ((ch = inStream.read()) >= 0) {
System.out.print((char) ch);
}
inStream.close();
}catch(Exception e){System.out.println("error"+e);}
}catch (Exception e) {
e.printStackTrace();
}
}
}
请各位大虾一定要帮忙解决,分不是问题!
|
http://www.csdn.net/oldexpert/TopicView.asp?id=87559&table=200101
|
帮你up
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。