Java Proxy Internet access

Source: Internet
Author: User

According to the Apache official JAVAAPI, the agent should be created as follows

Socket socket = new socket (new Proxy (Proxy.type.socks,new inetsocketaddress ("10.161.32.26", 8080));
try {
Socket.connect (New Inetsocketaddress ("http://www.baidu.com", 80));
System.out.println (socket.isconnected ());
catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

10.161.32.26 LAN Agent ip,8080 LAN proxy port

But unfortunately, this method I tried, rice useful, always error java.net.SocketException:Software caused connection Abort:recv failed;

Socket "If not in accordance with their own package under the" mode//The address is the proxy server's address socket socket = new Socket ("10.1.2.188", 80); Write and content is to follow the HTTP request protocol format content, request Baidu Socket.getoutputstream (). Write (New String ("Get http://www.baidu.com/http/1.1\r\n\r\ N "). GetBytes ()); byte [] bs = new byte [1024]; InputStream is = Socket.getinputstream (); int i; while ((i = Is.read (BS)) > 0) {System.out.println (New String (BS, 0, I));} is.close ();

Lazy, the rest of the direct send link

http://b-l-east.iteye.com/blog/1199237

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.