ola galera tenho q fazer um proxy e estou meio perdido. procurei no google e aqui no forum e o achei foi um codigo q nao sei fazer funcionar algume pode me ajudar a fazer um proxy?
galera agora vendo melhor esse codigo e para a aplicação passar por um proxy nao é?
import java.util.Properties;
import java.util.Date;
import java.net.URL;
import java.net.URLEncoder;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.io.DataInputStream;
import java.io.DataOutputStream;
// This is a simple example that shows how to get HTTP connections to work
// with a proxy server. If all goes well, we should be able to post some
// data to a public cgi script and get back the resulting HTML. If anyone
// knows some "gotchas" when combining Java and proxies, I'd love to hear
// about them. Send your thoughts to kurr@ctron.com.
public class ProxyTest
{
public static void main( String argv[] )
{
try
{
// Enable the properties used for proxy support
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "proxy2" );
System.getProperties().put( "proxyPort", "85" );
// URL to a public cgi script
URL url = new URL("http://hoohoo.ncsa.uiuc.edu/cgi-bin/post-query/");
URLConnection connection = url.openConnection();
// enter the username and password for the proxy
String password = "username:password";
// base64 encode the password. You can write your own,
// use a public domain library like
// http://www.innovation.ch/java/HTTPClient/ or use
// the sunw.server.admin.toolkit.security.BASE64Encoder
// class from JavaSoft Java Web Server.
String encoded = base64Encode( password );
// Set up the connection so it knows you are sending
// proxy user information
connection.setRequestProperty( "Proxy-Authorization", encoded );
// Set up the connection so you can do read and writes
connection.setDoInput( true );
connection.setDoOutput( true );
// open up the output stream of the connection
DataOutputStream output = new DataOutputStream(
connection.getOutputStream() );
// simulate a POST from a web form
String query = "name=" + URLEncoder.encode(
"Ronald D. Kurr" );
query += "&";
query += "email=" + URLEncoder.encode( "kurr@ctron.com" );
// write out the data
int queryLength = query.length();
output.writeBytes( query );
output.close();
// get ready to read the response from the cgi script
DataInputStream input = new DataInputStream(
connection.getInputStream() );
// read in each character until end-of-stream is detected
for( int c = input.read(); c != -1; c = input.read() )
{
System.out.print( (char)c );
}
input.close();
}
catch( Exception e )
{
System.out.println( "Something bad just happened." );
System.out.println( e );
e.printStackTrace();
}
}
}
grato