Results 1 to 17 of 17
- 04-05-2008, 03:18 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
reading URL using java through proxy server
hi all:)
i made a java application through user can access webpage through proxy server, but this works for only some pages like (http://www.iita-conference.org,yahoo.com,iiitk.ac.in etc) it not works for like rediff.com, ieeeexplore,orkut etc. i also post the code plz tell me where is the problem? why it not works for all URLs?
if possible plz send code too.
package ieee;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author sknavin
*/
public class Main {
/**
* @param args the command line arguments
*/
private static String loadPage(URL parURL) throws Exception {
Properties sysProps = System.getProperties();
sysProps.put("proxySet", "true");
sysProps.put("proxyHost", "172.31.1.3");
sysProps.put("proxyPort", "8080");
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("userID","password".toCharA rray()));
}
};
Authenticator.setDefault(authenticator);
long lTime = System.currentTimeMillis();
StringBuffer sb = new StringBuffer("");
String http = parURL.toString();
// Create a connection.
HttpURLConnection urlConnection =
(HttpURLConnection) parURL.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestProperty("USER-AGENT", "Mozilla/2.02Gold (WinNT; I)");
//
urlConnection.setRequestProperty("Content-type", "application/x-www-form-urlenCcoded");
urlConnection.setAllowUserInteraction(true);
urlConnection.connect();
InputStream in =
((HttpURLConnection) urlConnection).getInputStream();
int length = urlConnection.getContentLength();
for (int n = 0; n < length; n++) {
sb.append((char) in.read());
}
return sb.toString();
}
public static void main(String[] args) {
try {
// type your intended url here
URL url = new URL("http://www.iita-conference.org/");
String s = loadPage(url);
System.out.println("S=" + s);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
}
}
}
- 04-08-2008, 01:42 PM #2
Hello asheesh,
Welcome to the Java Forums.
It seems to me this is because the sites are blocking connectings from programs that are not web browsers. What you need to do is to trick these sites into thinking your program is a web browser.
Try this:
Note this bit of code:Java Code:import java.net.*; import java.io.*; class httpconnect { public static void main(String[] args) throws Exception { URL url = new URL("http://www.anywebsite.com/"); URLConnection spoof = url.openConnection(); spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" ); BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream())); String strLine = ""; while ((strLine = in.readLine()) != null) { System.out.println(strLine); } in.close(); } }
This is what tricks the sites into thinking you are using a web browser.Java Code:spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
I'm sure this will fix your problem!Did this post help you? Please
me! :cool:
- 06-20-2008, 02:04 PM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 121
- Rep Power
- 0
- 06-23-2008, 01:03 AM #4
face same problem
Sarinam: Stick with sites that will let you do a little bit. Trying to spoof can get you on hotlists too easily because of people who intentionally break protocols.
Most sites do not have the time or patience to separate beginners and so on and if they did do not wish to get involved in all the details. If you really want to do something along the lines of communicating with a server you should be sufficiently skilled to either hire a server or write one yourself.
The sample code has an http server already in the docs that ship with the JDK - and as well it implements some advanced cryptographic authentication that often is sold for hundreds of dollars.
If you want help writing a server, we can do that and will do so eagerly to keep you moving forward. There will be a forum here for that purpose.
- 06-23-2008, 06:19 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 121
- Rep Power
- 0
- 06-27-2008, 11:30 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 121
- Rep Power
- 0
- 06-27-2008, 06:47 PM #7
download sample server
That might even compile or someting. There are no methods, no activity ~ we have a great challenge in determining what and how to do it. It is telling of the power of the Java Libraries ( classes provided with the development kit ) that we can do https: with the sample server. I have not figured out how to do that, right now I am writing a Servlet, it will run on a sample code server designed to host servlets.Java Code:class SimpleSample { Server SERVER; Client CLIENT; SimpleSample() { SERVER = new Server(); CLIENT = new Server(); SERVER.start(); CLIENT.start(); } public static void main( String[]args) { SimpleSample simpleton = new SimpleSample(): } } class Server extends Thread { public void run(){} } class Client extends Thread { public void run(){} }
It runs locally, thus achieving a development platform for testing.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 06-27-2008, 08:30 PM #8
I wrote a proxy server long ago, but was unable to get it to work with https. I haven't looked at the new classes and methods available since 1.4?.power of the Java Libraries ( classes provided with the development kit ) that we can do https:
Could you lead me to what I need to make my server work with https?
Thanks,
Norm
- 06-28-2008, 06:08 AM #9
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 06-28-2008, 04:43 PM #10
Proxy server is in sample code.
This is over my head so I am doing the best available skills:
C:\.......\.....\Server.java ( sample sources in jdk install )Java Code:public abstract class Server { ServerSocketChannel ssc; SSLContext sslContext = null; static private int PORT = 8000; static private int BACKLOG = 1024; static private boolean SECURE = false; Server(int port, int backlog, boolean secure) throws Exception { if (secure) { createSSLContext(); } ssc = ServerSocketChannel.open(); ssc.socket().setReuseAddress(true); ssc.socket().bind(new InetSocketAddress(port), backlog); } //.....
Probably it is JKD - 5.x comments state @version 1.2, 04/07/26 ( some date, huh? )
I will google it: Secure Internet Programming with Java 2, Standard Edition (J2SE) 1.4
{snippet from cited url}
ClientHello: The client sends the server information such as SSL protocol version, session id, and cipher suites information such cryptographic algorithms and key sizes supported.
.......
sounds like what one could use to proxy across https - a very appealing idea for any site with a need to maintain business standards.
{edit: probably would need two servers running in same process, may not be achievable }Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 06-28-2008, 05:51 PM #11
Thanks for the info. Will have to look at all that.
PS. I need a text for Java 1.5 and 1.6, can you recommend any?
My current library is old: 1.2
Thanks,
Norm
- 06-28-2008, 06:08 PM #12
Hi,
Try one more thing, i am not sure if it works..
In the internet options->connections->LAN Settings.
Check the "use a proxy Server" and Advanced button gets enabled. click on advanced button and enter "localhost" or the IP addr in "Do not use proxy Server for addressing begining with".
We do the same for our Client-Server Application.To finish sooner, take your own time....
Nivedithaaaa
- 08-14-2008, 07:12 AM #13
Hello zlanhgn,
Please reply in English so that everyone can understand, not evryone here will be aware of your language.To finish sooner, take your own time....
Nivedithaaaa
- 08-20-2008, 10:30 AM #14
User has been banned. Unless the topic was Chinese aerospace board meetings. Please report posts that are inappropriate - it is a tremendous help to us. :)
Last edited by CaptainMorgan; 08-20-2008 at 10:34 AM.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 08-20-2008, 10:58 PM #15
In general, doing a proxy for HTTPS is hard. And sometimes, its impossible, as SSL is aimed at preventing "man in the middle attacks" and a proxy is exactly a man in the middle.
I debug my stuff completely using just HTTP and after it full works, turn on SSL. If I've really got the code working, its just works.
- 08-24-2008, 03:45 PM #16
text recomendation for 1.5+
Use Cay S. Horstmann. Possibly anything by Manning if you have the time and budget. There is a four volume set by O'Reilly that is rather exhaustive in it's coverage but may not cover anything past 1.2 The general approach I would advise for someone of your skills is to get the two volume set by Sedgewick, such work exceeds the power of directly using the libraries.
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 04-25-2010, 02:15 PM #17
Member
- Join Date
- Apr 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Does OS intervene when reading Java text files
By Tina G in forum Advanced JavaReplies: 1Last Post: 04-07-2008, 02:29 PM -
reading dir in java applets
By willemjav in forum Java AppletsReplies: 3Last Post: 02-07-2008, 12:36 AM -
reading textfile from java problem
By saytri in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:13 AM -
Question abt.reading xml file using java
By gvi in forum Advanced JavaReplies: 6Last Post: 11-08-2007, 05:48 PM -
Help with IRC server in java
By mathias in forum NetworkingReplies: 1Last Post: 08-07-2007, 06:51 AM


LinkBack URL
About LinkBacks


Bookmarks