This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes HttpConnection returns null  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpConnection returns null  " Watch "HttpConnection returns null  " New topic
Author

HttpConnection returns null

lekkie Nakel
Greenhorn

Joined: Jan 23, 2007
Posts: 15
I was trying to open a page and read from the stream.

Actually, the page returns different type os response. When a transactionis succesful it returns 200 if the transaction has some problems it sends dsome other response code (other than 200).

I want to be able to read the stream (content of the stream) even though the response code is not 200. I discovered if I open the url with the URL library or, once the response code is not 200, it closes the stream, hence any attempt to read it throws exception

However, I tried opening the stream from with httpconnection
HttpConnection conn = (HttpConnection)
Connector.open(req,Connector.READ,true);

but conn returns null.

why is that.

I am behind a proxy, so I set the system property:
System.setProperty("http.proxyHost","172.16.10.2");
System.setProperty("http.proxyPort","8080");

before calling connector.open

Thnx
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Is this really your code:

or are you giving us some red herrings? There's no Connector class in the J2SE and HttpConnection doesn't have an open method. I suggest you tell the details because the better question you ask, the better answer we can give.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
lekkie Nakel
Greenhorn

Joined: Jan 23, 2007
Posts: 15
Sorry, my err.

But HttpConnection can only b found in j2me. So am talkin abt j2me httpconection (it is only httpURLconnection that is in j2se)

I was wondering if I can retrieve the message that is sent when an httpURL connection returns a response codes other than 200?

I know it throws an ioe exception when a response other than 200 is returned, is there a way to retrieve the message returned by a servlet with response code 401?

If I cant get the message, what other method can I use connect to a server and still open the stream after it has thrown the err?
[ February 14, 2007: Message edited by: lekkie Nakel ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Again, you aren't giving us the whole story. Which J2ME API are you using? There are several.
 
Don't get me started about those stupid light bulbs.
 
subject: HttpConnection returns null
 
Similar Threads
A simple J2me Httpconnection not working - try for yourself
Problem using http post over j2me
Odd Problem - HttpConnection functionality
Using J2me/Kssl/Ksecurity on Palm O/S
X509CertificateImpl CastException in JSP