简体   繁体   English

如何使用Java连接到代理服务器

[英]How to connect to proxy server using Java

I want to write a java(SE) program to connect to a proxy server, lets say 123.123.123.123:8080. 我想编写一个java(SE)程序来连接代理服务器,比方说123.123.123.123:8080。 How am I going to achieve that? 我将如何实现这一目标? What is the protocol between my machine and the proxy server? 我的机器和代理服务器之间的协议是什么? What is the Java framework's class could be in use? 什么是Java框架的类可以使用?

since java 1.5,you can use java.net.Proxy class to create proxy. 从java 1.5开始,你可以使用java.net.Proxy类来创建代理。

Proxy proxy=new Proxy(Proxy.Type.HTTP, new InetSocketAddress("123.123.123.123", 8080);
URL url = new URL("http://www.example.com");
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
uc.connect();

reference 参考

Java 5中的网络代理配置的权威参考是Java Networking and Proxies页面。

Yes proxy server is a web server... Whenever u send a request through your browser to get some resource in the particular web server(say www.google.com),the request is send to the proxy server instead to sending the request directly to the google server..the proxy server process this request,send them to the gooogle server,receives the response and then send the response back to the browser. 是的代理服务器是一个Web服务器...每当您通过浏览器发送请求以获取特定Web服务器(例如www.google.com)中的某些资源时,请求将发送到代理服务器而不是直接发送请求到谷歌服务器...代理服务器处理此请求,将它们发送到gooogle服务器,接收响应,然后将响应发送回浏览器。 Proxy server is basically used to corporate fields to restrict the accesss to specific websites,to keep a track of the internet used by a particular associate,Also it saves some commoonly used webpages in a cache file,so that when another request comes,then instead of connecting to the required server,it get the webpage fron the cache file..Hence it saves the time.Also it scans the incoming data from any server for malware before submitting it to the client(browser).To check if ur company is using proxy server,u can go to the internet explorer setting ->Connections ->LAN Settings 代理服务器基本上用于公司字段,以限制对特定网站的访问,跟踪特定关联者使用的互联网,还可以在缓存文件中保存一些常用的网页,以便在另一个请求到来时,连接到所需的服务器,它从缓存文件中获取网页。因此它可以节省时间。在将其提交给客户端(浏览器)之前,它会扫描来自任何服务器的传入数据以查找恶意软件。检查您的公司是否是使用代理服务器,您可以转到Internet Explorer设置 - >连接 - >局域网设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM