UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Java
  • » HttpURLConnection problem

#1 2008-04-29 10:53 AM

Manoj_Gaur
Guest

Re: HttpURLConnection problem

Hi folks,

I am facing very strange problem thats may be concerning to OS. Actually I have piece of code that perfectly working in Windows environment but failed in UNIX.
    When I called the method getContentType(), its returning null in UNIX but retruned "text/comma-separated-values" in windows.
For have a look:-

URL url = URLUtil.makeURL(strUrl);
        HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
        httpURLConnection.usingProxy();
        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.setAllowUserInteraction(false);
        httpURLConnection.setDoInput(true);
httpURLConnection.setRequestProperty("Content-type","text/comma-separated-values");
        Log.customer.debug("HttpURLConnection" + httpURLConnection);
       Log.customer.debug("HttpURLConnection Content Type" +      httpURLConnection.getContentType());         
        InputStream fromServer = httpURLConnection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(fromServer));
        Log.customer.debug("InputStream Return Value" + in);     

Here also I am not able to get any value for getInputStream() method also in UNIX environment.

Please help me, I need it's very soon.
Thanks in advance.

#2 2008-04-29 01:04 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,230

Re: HttpURLConnection problem

It probably has something to do with the difference in Java version installed and
used. Try upgrading it to a newer version or something, maybe they added it only
later.

Offline

#3 2008-04-29 01:46 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: HttpURLConnection problem

httpURLConnection.setRequestProperty("Content-type","text/comma-separated-values");

Just a pure guess: could it possibly be a case-sensitive/insensitive issue where it
varies by platform?  Because, the true proper HTTP header is "Content-Type", with
capital "C" and "T", both...  Of course, I believe it's either a requirement or at least a
recommendation that you be case-insensitive regarding header fields...  But, maybe
on whatever platform you're on, they don't for some reason... *shrug*

Alternatively, perhaps "text/comma-separated-values" isn't recognized as a valid
content type on one platform, while it is valid on the other...  Not sure if Java cares
about configured MIME types from "/etc/mime.types" or "~/.mime.types" or wherever
your particular Unix system configures such things...  But, perhaps it's something
to consider, anyway...  Try adding "text/comma-separated-values" and see if that
helps...

Offline

#4 2012-09-10 11:05 AM

abc
Guest

Re: HttpURLConnection problem

Hi,

Was any solution, found for this. Facing the same issue. Happens for secured protocol (https) URL. The versions of Java on both machines is the same.

  • Index
  • » Java
  • » HttpURLConnection problem

Board footer

Powered by FluxBB