如何使用 php 和 java 从代理服务器连接


How to connect from proxy server using php and java?

我必须使用php和java通过代理服务器连接到互联网.....

由于我们必须在我的项目中的各种文件中使用互联网连接。

有什么方法可以在公共文件中编写用于通过代理服务器连接的程序,我们可以在任何地方调用该文件?

对于 php 和 java。

谁能帮我?

提前感谢...

谷歌是你的朋友!

.PHPhttp://www.php.net/manual/en/function.stream-context-create.php#92586

$opts = array('http' => array('proxy' => 'tcp://127.0.0.1:8080', 'request_fulluri' => true));
$context = stream_context_create($opts);
$data = file_get_contents('http://www.php.net', false, $context);
echo $data;

.JAVAhttp://jaydeepm.wordpress.com/2009/08/08/url-connection-via-proxy-the-java-1-5-way/

String proxyHost = "proxy.xyz.co.in"; //replace with your proxy server name or IP
int proxyPort = 8080; //your proxy server port
SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
Proxy httpProxy = new Proxy(Proxy.Type.HTTP, addr);
URLConnection urlConn = null;
BufferedReader reader = null;
String response = "";
String output = "";
URL url = new URL("www.google.com");
//Pass the Proxy instance defined above, to the openConnection() method
urlConn = url.openConnection(httpProxy); 
urlConn.connect();
reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
response = reader.readLine();
while (response!=null) {
    output+= response;
    response = reader.readLine();
}   
System.out.println("Output: " + output);