Link to home
Start Free TrialLog in
Avatar of monica73174
monica73174

asked on

Java Socket unknown host

I am trying to open a web page with a socket and no matter what url I use I get unknown host exception.  

I have made the code as simple as I can just to take it step by step. Any suggestions for why this keeps throwing that exception?

import java.io.IOException;
import java.net.*;
import java.util.Scanner;
import java.io.*;

public class soc {


	public static void main(String[] args) {
		
		try {
			String urlString = "http://finance.yahoo.com/q";
			Scanner sc = new Scanner(System.in);
			
			Socket http = new Socket(urlString,80);
			

			
			
			
			
			
			
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of monica73174
monica73174

ASKER

Even when I take the http off it still gives uknown host exception.
ok when I take the /q off that works.
ok when I take the /q off that works.
Yes, the q is not part of a hostname
You still shouldn't be using a Socket unless you've a good reason
It is a requirement.  I just am not sure how to now call the page with the /q and send parameters to grab a stock price.
It is a requirement.  
??
Then you're going to have to implement raw http. Good luck
:)