HttpURLConnection not connecting to all sites

Hi folks,
I have a small class which takes a URL as commandline input and outputs the HTML to stdout:
import java.net.*;
import java.io.*;
public class URLReader {
    public static void main(String[] args) throws Exception {
     URL url = new URL(args[0]);
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     conn.setDoInput(true);
     conn.setDoOutput(true);
     OutputStream os = conn.getOutputStream(); // Line 1
     os.close(); // Line 2
     conn.connect(); // Line 3
     BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null) {
          System.out.println(inputLine);
     in.close();
}If I try this:
java URLReader http://www.asp.com
I get the error:
=====
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL: http://www.asp.com
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:575)
at URLReader.main(URLReader.java:18)
=====
But, if I comment out the lines marked as Line 1, Line 2 and Line 3 it works fine and returns me the HTML.
Why would opening the Output Stream cause this?
Thanks in advance!
Musafir

Thanks for the response - sort of what I was guessing.
But, to me this behaviour is a bit counter-intuitive.
If I am making a GET request (in the request header),
then the request body should simply be ignored. To
disallow it altogether and produce errors is, IMHO,
undesirable behaviour.Some people are more paranoid that others and like to lock things uo tight.
What is more, it works for a very large number of
sites - www.bea.com, www.slashdot.org. It even works
for www.microsoft.com and www.msdn.microsoft.com!!Again it depends on the people running the site.
As a follow-up, what would I be doing in my Server
Side App to disallow request bodies when making a GET
request? Is it a Web Server setting?It can be done in the web server configuration or handled with in the code.
Thanks for the tip! Warm regards,
Musafir

Similar Messages

  • I've been working on our church website and suddenly, my computer will not connect to the site. I keep getting a message saying that the the connection to the server was reset while the page was loading. Does anyone have any ideas of how I can fix this?

    I've been working on our church website and all of a sudden this week, my computer will not connect to the site. I keep getting a message saying that the the connection to the server was reset while the page was loading. Does anyone have any ideas of how I can fix this?

    The "The connection was reset" error message can be caused by a bug fix for the BEAST (Browser Exploit Against SSL/TLS) attack that the server doesn't handle.
    *[[/questions/918127]]
    *[[/questions/918028]]

  • IPAD2 not connecting to some sites since IOS update

    Since the recent IOS 8 update, my IPAD will not connect to some sites.  It reads servere not found.  I'm trying to get onto my work site which is very important.  Now, my IPAD seems useless for work.  I have turned off and back on which did not help.  I have read that resetting it doesn't help either.  Please help.

    i checked for updated firmware on the d'link dir-615 router back in september when this first happened (after the ios6 update) but the firmware was already up to date - although the last update was 2009. 
    This was my first clue.
    After further research, I discovered that all DIR series products have been discontinued by D'Link.  This means that when apple is preparing for a software update, it requests all software/hardware specs from wifi router companies like D'Link, Netgear, Garmin, Cysco, etc.  Since D'LInk no longer produces DIR series routers, they did not provide the info.  D'Link only provided info for it's newest line of wireless routers. 
    Leaving all existing DIR users in the dust, with a failed strategy that we'd all buy the new line of wifi routers.
    Yesterday, I purchased an Apple wifi router, although pricey at $99, i plugged it in, typed the network name and pw want to use, and it was up and running in less than 5 minutes.  The apple router will recieve software/firmware updates just as my iphone, macbook, & ipad does. Everything is working perfectly, and the higher price is worth the convenience and reliability.
    If anyone makes it this far, the only thing left would be to check with your internet service provider (comcast, RCN, etc) and make sure you have the most up to date modem.  some folks are unable to send text & pic messages on wifi using an out of date modem. (i didn't have to replace mine, but i'm also not having this issue now that i have the new apple wifi router.)
    Hope this helps at least a few people out there.

  • Following hard drive failure on iMac running Maverick I have recovered from TimeMachine backup but now app store does not connect. All other internet connections normal. Does anyone know of a fix?

    following hard drive failure on iMac running Maverick I have recovered from TimeMachine backup but now app store does not connect. All other internet connections normal. Does anyone know of a fix?
    Also mail not loading. The error report suggests that I look for updates from the app store?

    http://www.apple.com/support/mac/app-store/contact/

  • Flash player 11.0.1.152 not working on all sites. Using Mac OS 10.5.8

    What am I missing?  Flash didn't work properly on previous version either.  I use google chrome primarily but flash does not work on all sites using Firefox or Safari either.  I have a Macbook Pro operating on 10.5.8.  I'm sure it's probably a simple fix but I just haven't found it.  Appreciate any help on the matter. 

    I have spent countless hours trying to get my flash player working and have tried EVERY kind of possible answer through many forums and websites to solve this. Does adobe have anything currently that will solve this flash player problem?? I have the lastest version of Safari 5.1.1. and I have the lastest version of adobe flash player 11.0.1.152, I have even tried the debugging installs adobe put out for flash player. I have tried the "working around lion flash player video thing" where you try private browsing. I have tried going into system preferences and entering into the flash player settings in the storage tab the allow this sites, etc. NOTHING HAS WORKED!! I still get my local storage pop up message whenever I try and watch a you tube or any site that has flash video on it, that flash player settings box still pops up and is stuck on my screen and I cant click allow or deny or get it off. So many people I have read have the same problem and I only the same answers pop up that I have tried again and again, does anyone have a real resolve to this yet??? PLEASE PLEASE PLEASE HELP.

  • TS1538 Still not connecting after all these steps were done, what is the solution?

    Still not connecting after all these steps were done, what is the solution?

    Tried a different cable, this cable will now charge the ipod, but will not be recognized by the computer as even being a drive.
    haven't tried a different computer because I really don't want itunes instaled on it.

  • Firefox keeps not responding on all sites

    firefox keeps not responding on all sites , even when i scroll up and down. it's been going on for 2 weeks now. can they fix this

    Firefox & Java, Firefox & Flash Player, Firefox & Plugins, Firefox & The rest of the world... When will these problems end?!

  • TS1398 hi, my iphone is not connecting to wifi. there is no problem with the connection of wifi. i tried so much but the connection is not stable. some times it connect and sometimes not connecting at all. if connected also its disconnecting again.pls hel

    hi, my iphone is not connecting to wifi. there is no problem with the connection of wifi. i tried so much but the connection is not stable. some times it connect and sometimes not connecting at all. if connected also its disconnecting again.pls help

    At the very least, I recommend you restart your router, (your internet box).
    More detail on your problem is needed - are you in a submarine? On the moon? On a tropical island?
    You can help yourself by providing as much info as you can about your present situation - what kind of router do you have? Have you moved it? DId you update it?  Did you do anything to change your setup, and if you did, what?

  • Keep Acrobat from repeatedly warning me about not connecting to external sites thru pdfs

    When I use Acrobat XI Pro to create a pdf from an original that has links to the internet (usually ad sites) the resulting pdf is blocked by Acrobat from connecting to a number of sites. That is fine, since I do not want my pdfs to connect to external links unless it is a site that I specifically authorize. The problem is that as I scroll through the pdf Acrobat keeps warning me by presenting a dialog box that says "Acrobat is blocked from connecting to (name of site)". I cannot continue scrolling until I manually close the dialog box. This repeatedly interrupts my scrolling. I would like to not have Acrobat repeatedly warn me about this. Can I block these annoying warnings?

    In Acrobat 11 Pro "change settings" has three options, "Allow PDFs to Access All Websites", "Custom Setting" and "Block PDFs' Access to All Websites". Under "Custom Setting" it is true that one can enter specific sites at trusted in that access is allowed. Also, the options for sites not listed as trusted sites are to "Always Ask", "Allow Access" and "Block Access". However, even when I bypass "Always Ask" and choose "Block Access", Acrobat opens a dialog box and notifies me when it blocks access to one of the sites not on the explicitly trusted list. Acrobat does this every time and each time I have to manually close the dialog box to continue scrolling through the pdf.  I may not have made it clear, but I do not want to be notified that Acrobat has blocked access to a site and to have to interrupt what I am trying to do by manually closing the dialog box. If I wanted any notifications I would have chosen "Always Ask".  I hope that my issue is now more clear. Your suggestions are well taken, but do not address the problem. If you have any additional ideas I will be glad to see them and I appreciate your trying to address my question. 

  • EPrint not connected but all other functions working

    I have just set up the All-in-One HP216B printer. All wireless connections are perfect and I can print from multiple wirelessly connected laptops and one desktop connected via ethernet to the router. All basic functions of print, sca, copy work. I followed the set up for the Web Services and that seemed to work. The wireless network test shgows everything to be in perfect order. I have an IP address etc. However when I am in the ePrintCentre the printer is showing as not connected and when I attempt to send an email to the printer it shows up as pending in the Print Jobs. The printer is clearly just not connected to the internet and that is also verified by the fact that the PrintApps cannot download the prints from the hpcentre web site.
    I have switched the printer off and on again. I have removed the printer and added it again - all to no avail. I have looked through the forums and still have no success.
    Anybody any ideas ?
    This question was solved.
    View Solution.

    OK it works now. Not sure why or how but repeated attempts at switching printer on and off coupled with resetting email address has worked. I also changed back from specifying allowable emails addresses to allowing all and today my prints arrived. Curiously I also have to switch the printer on ana off to reactivate the scan connection to my desktop and laptops all connected via the router.
    I am semi happy as this is not a plug and play or seamless solution that is described on the box

  • Could not connect to a site which doesnt exist anymore (SCCM 2012)

    Hi,
         I am running my SCCM in a hyper-V virtual environment and I
    could no longer connect to a site (for eg. abc.def.com) when I start my Configuration Manager Console .
         Firstly, when I previously configured SCCM during the installation process, I configured it to join a forest, which I created, called (for eg. abc.def.com). This computer is a domain controller. 'abc.def.com' does
    not have Internet connection.
         I had some network problems and due to some project changes, I have to remove abc.def.com and
    connect to another network which has Internet access because I want to use Windows Intune too. So, now when I start my ConfigMgr, I naturally could not connect to 'abc.def.com'.
         The question now is: "what do I have to do now to allow me to use my SCCM again?"
    Thanks.

    "I have to remove abc.def.com and connect to another network"
    It is very obvious that you cannot connect to the previous network. You could have added another network adapter in your hyper-v for internet connectivity. If you have changed the domain then you need to install a new domain controller and install SCCM from
    scratch.
    Prajwal Desai, http://prajwaldesai.com

  • Ff6 beta is taking a very long time or not loading at all sites from links or bookmarksmarks

    firefox 6 beta auto updated now when I click on links or book marks site either take a very long time to load or do not load at all.When I tried to log into my back acct. it never loaded.

    No clue why the final processes have suddenly started to take so long. Two things I'd try: a) capture from an older tape to see if some problem with the new tape is at fault.  And b) check the health of your RAM and the hard drive.
    The red frame sounds a bit like a glitch we used to have in OnLocation (actually in its predecessor HDV Rack) which was caused by a partial GOP. But that was a product of HDV Rack recording from the live video stream. It turned out that HDV cameras intentionally interrupt the data stream for an instant upon starting to record--specifically to avoid recording a partial GOP to tape. So my gut says that the tape has partial GOPs at the points where you stopped/started recording.

  • FLASH PLAYER NOT WORKING WITH ALL SITES

    Text
    Text
    I INSTALLEDTHELATEST FLASH PLAYER BUT IT SEEM TO NOT BE
    WORKING ON ALL SITES.I'M STILL GETTING
    MESSAGES TO DOWNLAD THE LATEST VERSION OF FLASH PLAYER EVEVN
    THOUGH I ALREADY HAVE IT.
    SOME SITES WILL WORK FINE BUT OTHERS WILL TRY TO LOAD THEN
    FAIL THATS WHEN I GET
    THE MESSAGE TO INSTALL THE LATEST FLASH PLAYER.
    WHEN TURN OFF THE PC THEN TURN IT ON LATER THE SITES THAT
    WERE WORKING NOW GIVE MW THE SAME ERROR MESSAGE TO GET THE LATEST
    FLASH PLAYER.
    I'M RUNNING XPSP1 ANDHAVE NEVER HAD ANY PROBLEMS IN THE PAST
    FLASH PLAYER ALWAYS WORKED
    WHAT NOW?

    I had similar issues, try the solution in this thread...
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=44&catid=184&threadid =1245905&enterthread=y

  • I'm having three issues: spellcheck goes off, lastpass not working on all sites, and message boards not working correctly

    I'm having three issues with Firefox. I had the latest 10.1, and I just tried Aurora, but that didn't solve my issues.
    1) Spell checker keeps going off on messages boards. This happens frequently on 247 sports boards. I enable spell check, make a post, and it's off again when I make another post.
    2) On the same 247 board, when I make a post (by clicking the "post reply" button, nothing happens. To get it working I actually have to quit the site and go back in.
    3) LastPass plugin is no longer working on all sites. Site like Facebook and Yahoo all of a sudden Lastpass doesn't recognize as having usable fields.

    Hi,
    Please check if this happens in a [https://support.mozilla.org/en-US/kb/Managing-profiles new profile]. If it's okay, you can later [https://support.mozilla.org/en-US/kb/Recovering%20important%20data%20from%20an%20old%20profile?s=profile&r=1&e=sph&as=s copy the needed personal data] from the old profile. Firefox stores your personal data and settings in another location separate from its [http://kb.mozillazine.org/Installation_directory files/folder]. A new profile would have the default Firefox settings ('''Tools''' ('''Alt''' + '''T''') > [https://support.mozilla.org/en-US/kb/Options%20window '''Options'''], and [http://kb.mozillazine.org/About:config about:config] ), and usually would also be empty of any '''Extensions''' and themes ('''Appearance''') in Tools > Add-ons) and their settings. Also, a new profile would have no previous stored website data/settings etc., ('''Tools''' > [https://support.mozilla.org/en-US/kb/Clear%20Recent%20History '''Clear Recent History''']).
    [https://support.mozilla.org/en-US/kb/Profiles?s=profile&r=2&e=sph&as=s Profiles Howto]
    [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder & Files]
    [http://kb.mozillazine.org/About:config_entries about:config Entries]

  • Can not connect to web site to download shockwave page interrupt

    I am using mozzilla ans shock wave was deactivate then got deleted not I can not load a new version every time I try to download shock wave or flash the page will not connect?

    For Flash Player use
    Flash Player for Internet Exporer - ActiveX
    Flash Player for Firefox - NPAPI
    Flash Player for Mac OS X

Maybe you are looking for

  • Report on a .DLL file

    I need to run an inventory report on a specific .DLL file for all workstations at my site. I need the date and version of this file. How do I get ZEN inventory to grab and store this information to the database? Or if it's already in the database how

  • [SOLVED] ACPI handler.sh no longer working (Thinkpad X60 Tablet)

    Hello there, I recently did a few updates on my system to reduce power usage and get hdaps working. For some reason one of these changes must have broken ACPID in some way so that what I wrote in handler.sh no longer has any effect when I e.g. press

  • Opening Excel file in Numbers

    I placed an Excel file in Numbers iTunes file area and synchronized, but no files are found when I open Numbers on the iPad. Please advise. jmf

  • Mount External Hard Disk (connected in Windows Server) in Solaris 11

    Hello Solaris Admins, I have a 2 TB WD My Book External Hard Disk connected to a Windows 2008 Server and needs to mount it in Solaris 11 Server. For mounting a directory in File Server i am using the following Command mount -F smbfs "hostname;usernam

  • Code signing tools

    is it possible to just download the code signing tools? I've installed the SDK, but I can't find keytool or the javasign(?) commands. thanks.