Why can't I read the content of my HttpUrlConnection?

Hey all. I am having problems with the code below. I have run it through a tcp trace, so i know the responce I am getting from my
webservice i call.
The problem is, the Content Length http header in the webservice request is set to 0. There is a body in the request of the message.
When I try to do the input sream read, it always shows there is nothing in the unput stream! How can that be when there is a full responce in the body? Does the HttpUrlConnection just tell you there is nothing based on the Content Length header?
any help woule be very appreciated. Thanks!
import java.net.*;
import java.io.*;
public class Test {
public static void main(String[] args) {
try {
String urlString = "http://SomeInternalUrlICantShowYou";
URL url = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setUseCaches(false);
huc.setRequestMethod("GET");
huc.connect();
System.out.println(huc.getContentLength());
BufferedReader in = new BufferedReader( new InputStreamReader(huc.getInputStream()));
int i = in.read();
while(i!=-1) {
System.out.println((char)i);
i = in.read();
in.close();
huc.disconnect();
catch (Exception ex) {
ex.printStackTrace();
}

As I understand from your post that the remote server you are trying to access has the set the content-length in the header field as 0!!?? Seriously that I dont know how they did it. Might be when the reply is being send then they modify the response header.. That will be interesting to checkout how!! Anyways assuming that the Content-Length is 0 then below might be the possible explanation.
There is nothing wrong in your code. As per RFC 2068 (HTTP/1.1protocol)
section 14.14 Content-Length you will find that the applications SHOULD use this field to indicate the size of the message body to be transferred.
Hence the implementation of HttpURLConnection is that it creates a socket connection with the remote server and gets the Response Header. It reads the value of the COntent-Length field from the header. If the content-Length is ) then it assumens there is nothing more to read and hence reads nothing.
In your implementation you are using the input stream of the HttpURLConnection and not making a direct socket connection with the remote server.
It is due to this reason that when internally HttpURLConnection getrs the respose Header it fonds the value of the Content-Length as 0 and hence stops reading and consequntly your application also cannot read.
I Hope this answers your query.

Similar Messages

  • When I click on a link from a web page opened in Safari I get a blank black screen. Why can't I see the contents of the page?

    When I click on a link from a web page opened in Safari I get a blank black screen. Why can't I see the contents of the page?

    Is this any link in any page, or one particular link in a particular page?

  • Why can't I change the content for some songs when I click the Get Info button?

    Why can't I change the content for some songs when I click the Get Info button?  The information on the song, artist, genre is grayed out and will not allow me to alter the information.

    Hi htechadmin,
    Revcevied your PM and noted all details, Many Thanks.
    Getting this addressed by the team, either they will reply to you, here, or they shall email Or Call you.
    Regards,
    LP

  • HT204081 why can i not read the books i bought on itunes on my itunes/computer?

    i was just wondering why can i not read my books on my computer that i just bought online on the itunes store. do i have to download anything speffic?

    ibooks bought from Apple can currently only be read in the iBooks app on an iPad, iPhone and iPod Touch - so far Apple haven't made a Mac or PC reader for them, so you won't be able to read them on your Mac.

  • Why can't I use the content library in iMovie?

    I can use every other feature in iMovie except for the Content library. It is not in my side bar, and when i get it from the tool bar above the options are gray like I can't use them.

    Hello taigepeves,
    Thanks for using Apple Support Communities.
    If you're trying to get your Content Library to appear in iMovie, please make sure you have a movie project open, as it should then automatically appear.
    You can find titles, transitions, music, and maps in the Content Library. The Content Library is at the bottom of the sidebar once you open a movie project.
    If the sidebar is not already open, click Show in the toolbar.
    At the bottom of the sidebar, select an item from the Content Library.
    In the Browser, your selection appears (titles, transitions, and so on). Drag one to the timeline to add it to your movie.
    If you add a title, map, or globe, you can adjust settings in the Adjustments Bar which is located above the Viewer.

    If you add a transition, double-click it in the timeline to adjust its duration.
    To return to your video clips in the Browser, select an event in the sidebar.
    iMovie (2013): Tips For iMovie ’11 Users - Apple Support
    Take care,
    Alex H.

  • Why can't I see the contents in my Profile Folder when it says I have 144 megs in it?

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/951291]]</blockquote>
    Every since I upgraded to the latest version (19.0) of FireFox, I can't see the contents of my Profile. It says I have 144mb. FireFox is installed on MacBook Pro running Mac OS 10.6.8.
    I have even tried copying and pasting the files into a new empty folder. Command Info says 144mb but I don't see files. Somehow they are hidden? Any help is appreciated.

    Hello lakota85usa, the [http://kb.mozillazine.org/Profile_folder_-_Firefox#Mac profile folder is hidden Mac OS X 10.7 and above], not in your version(10.6.8), see if the "Showing hidden files and folders on Mac OS X" in the next link is helpful: http://kb.mozillazine.org/Show_hidden_files_and_folders#Mac_OS_X
    thank you

  • Why can't I get the content of my XML?

    Hi all. Here is a simple question. I have a XML document like:
    <!DOCTYPE WEATHER SYSTEM "vpn2.dtd">
    <TOTAL>
    <VERSION_OUTIL>
    1.1
    </VERSION_OUTIL>
    <VERSION>
    2.23
    </VERSION>
    </TOTAL>
    and I want to read 1.1 . I am sura that it is simple but not for me !!! Here is the code I test. I read the tag name but not the content could someone help me ?
    public TestDOM (String xmlFile) {
    // Create a Xerces DOM Parser
    DOMParser parser = new DOMParser();
    // Parse the Document
    // and traverse the DOM
    try {
    parser.parse(xmlFile);
    Document document = parser.getDocument();
    NodeList liste=document.getElementsByTagName("VERSION");
    for (int i=0;i<1;i++){
         Node temp= liste.item(i);
         System.out.println (i+"*********"+document.getNodeValue());
    System.out.println (i+"*********"+temp.getNodeValue()
    }

    What constitutes a node is kind of misleading:
    the NodeList you have got contains one ELEMENT_NODE and what you want to print out is the TEXT_NODE which in fact is a child of the ELEMENT_NODE
    If you try temp.getFirstChild().getNodeValue() it should work.
    Using getFirstChild() is kind of cheating in that I know the TEXT_ELEMENT will be the first child. Not sure if there is a more general/elegant solution.

  • Can my parents read the content of my messages after deletion from my phone?

    Hello everyone,
                             First off, I'd like to thank you kindly for actually checking into this forum, it means a lot. Secondly, I have looked up a lot of information on this question, and I've been getting A LOT of mixed messages. It is to my understanding, that even though my parents are the bill payer for my phone, they do not have any right to request forms which reveal the actual CONTENT of my text messages. They CAN however, see the time, date, and how many text messages. That is just to my understanding. If someone could answer this question, please do.
                                                                                                                                                     Thank you.

    I would just not text if you think they are going to ask verizon for what's inside them.
    P.S She should be glad that she gets a free phone at all, I was age not that long ago and mean it, not in some old guy kind of way and I had to pay for my cell phone. Kids think that they Should a free NEW 20000+ car for free when they are 16 and all this crap. I am not saying I did not want any thing like that, but if I did not get it, I did not act like they hated me and crap.

  • Why can't I read the topics on the discussion board?

    I'm registered and signed in, but I can't see the titles of the topics on the board. Is there something I'm doing wrong?

    aloeman . . .
    Welcome!!!
    Start here:
    http://discussions.apple.com/index.jspa
    Then choose the category you're interested in.
    Then you'll probably find several (or many) forums
    around that category. Just click on the forums you'd like to read,
    and you're all set.
    Hope this helps.

  • Why can't I print the content of a row in the ResultSet twice?

    An exception was thrown when I tried to print it twice like this:
    while (rs.next()) {
    System.out.println(rs.getString(1));
    System.out.println(rs.getString(1));
    }Why?

    An exception was thrown when I tried to print it
    twice like this:
    while (rs.next()) {
    System.out.println(rs.getString(1));
    System.out.println(rs.getString(1));
    }Why?The real question is: why would you want to do that? ResultSets shouldn't be printed like that. MVC separation says that printing is View, and ResultSet is persistence. Better to iteration through the ResultSet once, loading the data into an object or data structure, close the ResultSet in a finally block, and then pass the object or data structure for rendering (be that printing or JSP or Swing or whatever your View is).
    %

  • Why can't I read the Sticky Notes I put in my PDF?

    I've made PDFs before and added sticky notes, which I can go back to and read later.  But this time around, when I added sticky notes and saved the document, later on when I went back the sticky note image was there, but I couldn't access any of the note itself.  I thought maybe it had to do with an expired trial of Adobe Pro, but I've since upgraded and still can't read them.

    Hi bscraver,
    It could be that the opacity of the sticky note changed. Do the sticky notes appear if you choose Comments > Comments List? If so, try selecting one in the Comments List right-click and check the Properties. If the opacity is 0% increase it.
    Please let us know how it goes.
    Best,
    Sara

  • Why can't I read the text on some web pages?

    I'm using my laptop with a Vista OS and Firefox. Some of the text that appears on web pages seems to be rendered incorrectly on my screen. I'm hoping someone can tell me how this happens.
    Here is a [http://img840.imageshack.us/img840/151/54855858.jpg screen shot] of what the homepage for Digg.com looks like.

    I have the same problem which is one reason I still use IE8 (which has its own problems). I change my font to be bigger, and I use my toolbar on the side. Firefox apparently doesn't like this and squooshes the page together.
    I could do all sorts of research to figure out what is wrong, reconfigure Firefox, use the fonts it wants, install, zoom, uninstall fonts, and perhaps find apps to change the way it looks. I probably could set up my computer to satisfy the needs of Firefox.
    Nah. I like my computer to work for me! So, I have to go to IE a lot. I use FF for some things. IE for others.
    Good luckl

  • When I tried to install reader, it stopped and says I have a higher functioning program. Why can I not read the pdf's I need then?

    I tried to download reader for pdf files for school. It stops installing and cancels. It says that I have a higher functioning program and cancels installation. I still cannot view the material I need. How to I fix this?

    Are you trying to view the materials from within your browser? If so, read this: Configure browser to use the Adobe PDF plug-in

  • Help required please. "Itunes can not read the contents of my iphone"

    Greetings all,
    I know this question has been asked before and I apologize for asking again but all the solutions provided don't seam to work for me, can anyone help me please.
    I am receving the message: "Itunes can not read the contents of the iPhone. Go to the summary tab In iPhone Preferences and click restore torestore this Iphone to factory settings".
    Now a little about my iphone, Itunes and my laptop and what steps i havealready tried.
    I have an iPhone 4 running software 5.0
    My itunes version is 10.5.0.142
    I know these are not the most up to date versions but I have had this issue for almost 3 months now and updating the software back then was the first step I tried. I don’t believe updating to the latest will fix this issue as updating the last two times did nothing.
    Every so often after starting Itunes, The program will stop responding and will require the three finger death kill (CTRL, ALT, DELETE) to open task manager to end the task of Itunes. Once it shuts down, I restart the iTunes and it runs smoothly, apart from not reading my iPhone.
    When I run a diagnostic in itunes under the help tab, I get these fail messages:
    Network Connectivity test: Secure link to Itunes store fail
    Device connectivity test: Under support services: Itunes helper is not running. And under ports: No iPod, iPhone or iPad found.
    Device Sync test: No iPod touch, iPhone or iPad found.
    *See below for full diagnostic report*
    I have restored back to factory settings twice.
    I have shut down and restarted both my iPhone and laptop.
    I am running Windows 7 32-bit on my laptop.
    I am using ZoneAlarm as my fire wall, and have been disabling it when syncing my iPhone to prevent other error messages.
    The iPhone is plugged into a genuine Iphone USB cable and is plugged into a USB port not a USB hub on my laptop, I have tried plugging it into all 4 USB ports and this issue still persist. The Cable is less then 5 months old, is not frayed or damaged in any way, have also borrowed 2 other cables from friends and still the same issue.
    The iPhone does not even come up in windows explorer as a digital camera.
    The iPhone is NOT jailbroken
    I do not live close to a so called genius bar, however I have made the journey to them on 3 separate occasions last year when I first received my iPhone for a different issue, the so called genius's could not fix the problem so they just gave me a new (refurbished) iPhone, which did not extend my warranty. I will not be taking the iPhone back to them as I believe they can not resolve many issues, this is why I am reaching out to the power of the people in the wider apple community.
    I have read in other forums about ifunbox and other programs for jail broken iPhones to isolate folders “iTunesDB” and "iTunesCDB" and delete them. If this is the issue is there a way to access these files through windows explorer as my iphone is not jailbroken.
    I hope I have provided enough information and someone can help me fix this issue. If I have left anything out, please let me know. I thank everyone in advance for your patience and support.
    Thanks
    Hoggie27
    FULL DIAGNOSITC REPORT
    Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601)
    Hewlett-Packard HP Pavilion dv6 Notebook PC
    iTunes 10.5.0.142
    QuickTime not available
    FairPlay 1.13.35
    Apple Application Support 2.1.5
    iPod Updater Library 10.0d2
    CD Driver 2.2.0.1
    CD Driver DLL 2.1.1.1
    Apple Mobile Device 4.0.0.96
    Apple Mobile Device Driver 1.57.0.0
    Bonjour 3.0.0.10 (333.10)
    Gracenote SDK 1.9.3.494
    Gracenote MusicID 1.9.3.106
    Gracenote Submit 1.9.3.136
    Gracenote DSP 1.9.3.44
    iTunes Serial Number 001BAD14XXXXEA78
    Current user is an administrator.
    The current local date and time is 2011-11-16 10:04:53.
    iTunes is not running in safe mode.
    WebKit accelerated compositing is enabled.
    HDCP is supported.
    Core Media is supported.
    Video Display Information
    NVIDIA, NVIDIA GeForce GT 230M 
    **** External Plug-ins Information ****
    No external plug-ins installed.
    The drive H: Vodafone  USB SCSI CD-ROM Rev  USB is a USB 1 device.
    **** Network Connectivity Tests ****
    Network Adapter Information
    Adapter Name:    {97524DB0-B9DC-41DB-8AFA-0CE6938F7C95}
    Description:    PC
    IP Address:    (HAS BEEN REMOVED FOR PERSONAL REASONS)
    Subnet Mask:    255.255.255.255
    Default Gateway:    0.0.0.0
    DHCP Enabled:    No
    DHCP Server:   
    Lease Obtained:    Thu Jan 01 11:00:00 1970
    Lease Expires:    Thu Jan 01 11:00:00 1970
    DNS Servers:    10.143.147.147
            10.143.147.148
    Adapter Name:    {BFF0456E-DE42-4FEF-B1FA-1EA1C5EDEE42}
    Description:    Vodafone Mobile Broadband Network Adapter (ZTE)
    IP Address:    0.0.0.0
    Subnet Mask:    0.0.0.0
    Default Gateway:    0.0.0.0
    DHCP Enabled:    No
    DHCP Server:   
    Lease Obtained:    Thu Jan 01 11:00:00 1970
    Lease Expires:    Thu Jan 01 11:00:00 1970
    DNS Servers:   
    Adapter Name:    {D5511FFD-0CA8-4F62-B3CA-E90384FFCD03}
    Description:    Broadcom 43225 802.11b/g/n
    IP Address:    0.0.0.0
    Subnet Mask:    0.0.0.0
    Default Gateway:    0.0.0.0
    DHCP Enabled:    Yes
    DHCP Server:   
    Lease Obtained:    Thu Jan 01 11:00:00 1970
    Lease Expires:    Thu Jan 01 11:00:00 1970
    DNS Servers:   
    Active Connection:    PC
    Connected:    Yes
    Online:        Yes
    Using Modem:    Yes
    Using LAN:    No
    Using Proxy:    No
    SSL 3.0 Support:    Enabled
    TLS 1.0 Support:    Enabled
    Firewall Information
    Windows Firewall is on.
    iTunes is NOT enabled in Windows Firewall.
    ZoneAlarm Firewall is installed.
    Connection attempt to Apple web site was successful.
    Connection attempt to browsing iTunes Store was successful.
    Connection attempt to purchasing from iTunes Store was successful.
    Connection attempt to iPhone activation server was successful.
    Connection attempt to firmware update server was unsuccessful.
    The network connection timed out.
    Connection attempt to Gracenote server was successful.
    Last successful iTunes Store access was 2011-11-16 09:59:57.
    **** CD/DVD Drive Tests ****
    LowerFilters: Afc (1.0.0.2),
    UpperFilters: GEARAspiWDM (2.2.0.1),
    F: hp CDDVDW TS-L633N, Rev 0300
    Drive is empty.
    **** Device Connectivity Tests ****
    iPodService 10.5.0.142 is currently running.
    iTunesHelper is currently not running.
    Apple Mobile Device service 3.3.0.0 is currently running.
    Universal Serial Bus Controllers:
    Intel(R) 5 Series/3400 Series Chipset Family USB Enhanced Host Controller - 3B34.  Device is working properly.
    Intel(R) 5 Series/3400 Series Chipset Family USB Enhanced Host Controller - 3B3C.  Device is working properly.
    FireWire (IEEE 1394) Host Controllers:
    1394 OHCI Compliant Host Controller.  Device is working properly.
    Most Recent Devices Not Currently Connected:
    iPhone 4 (GSM) running firmware version 5.0
    Serial Number:    85107XQLA4S
    **** Device Sync Tests ****
    No iPod, iPhone, or iPad found.
    < Edited By Host >

    Hi AM_Kidd.
    Thanks for your reply.
    I have done a complete uninstall and re install of iTunes and all related apple programs from my laptop through control panel, add remove programs and also by going through program files and deleting all tracers of any left over folders remove programs may have missed.
    My apologies for forgetting to add this in my original post.
    Thanks again

  • "iTunes cannot read the contents of the ipod", How can I fix this?

    Hello everyone, I am having trouble with my iPod touch 32GB and getting iTunes to detect it. I'm using Windows 7.
    When plugging it in tonight, I got the message "iTunes cannot read the contents of the iPod (Name). Go to the summary tab in the iPod preferences and click restore to restore this iPod to factory settings". I attemped to do this, but I then got an iTunes error "3184" and was unable to install the iPod software.
    I've tried...
    - Using a different computer
    - Using a different USB cable
    - Rebooting the iPod
    Nothing seems to work. I've read a solution as to delete one of the iTunes files on the iPod, but the iPod doesn't show up in my Windows Explorer, so I am unable to do this. The computer does however charge the battery when I have the iPod plugged in. I'm also able to still listen to music on the iPod as well.
    One other note, I had the same thing happen to my previous iPod touch. I got my original iPod touch back in December 2010. In October 2011, the iPod just died one day and I was not able to turn it on at all or charge it. When I'd plug it into the computer, I got the exact same errors and was unable to restore the iPod. I sent it in to Apple as it was still under warrenty and they sent me a replacement. Now 3 months later it's happened again. Of course the warrenty starts from the day you purchase the original, so this is no longer under warrenty despite having it for only 3 months. The only difference this time is that the battery still charges and I can still turn it on and listen to music.
    Any ideas?
    Thanks

    hi Angie!
    hmmm. is there an Apple Store convenient where you can take the ipod for a check-up?
    love, b

Maybe you are looking for