views:

19

answers:

1

Hello.

I'm in the process of migrating some of our old code into Java and have become stumped on connecting to (what I believe are) MFC ASP ports.

In the old code this was done via CInternetSession, but I'm uncertain of what the Java equivalent would be.

As an example, the old code had the following:

CInternetSession sess;
pHttpConnect = sess.GetHttpConnection(m_WwwSite, m_port, m_Logon, m_Password);
... do stuff

Does anyone know what the best-fitting replacement for something like this would be? Looking around so far, it seems like I'd need to use some of the classes in servlet-api.jar, but I'd really appreciate an expert opinion before I start heading down a potentially fruitless avenue.

Thanks.

A: 
URLConnection conn = new URL("http://" + m_Logon + ":" + m_Password + "@" + m_WwwSite + ":" + m_port).openConnection();

If you don't want to do the string concatenation, you can use the URI constructor instead, then use toURL(). See URL, URI, and URLConnection.

EDIT: I fixed the missing http.

Matthew Flaschen
Howdy Matthew.Thanks for pointing me in this direction, looks like a much more appealing alternative to servlets. I'm a problem with authentication (java.net.MalformedURLException: unknown protocol: {myLogon}), but I'll try to take a crack at it myself before I ask again.Thanks again.
Neil McF
I was missing the http:// before, which is why you got the unknown protocol. By the way, servlets are a way of implementing Java web services (server side). Both CInternetSession and URLConnection are used on the client side.
Matthew Flaschen