Getting the response code from a http url connection

The following program bombs if it does not find a page
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/sadjhasjd.html");
HttpURLConnection client = (HttpURLConnection) yahoo.openConnection();
int resp_code = 0;
if(client!=null)
resp_code = client.getResponseCode();
I want to get the page that the yahoo returns if it cannot get the page.... just cut and paste the above address in a web browser and see what you get.....how can i get that page back....the above thing throws an IOException...............
thanks
sharad

The problem is it doesn't like .htm or .html for some reason.. I don't know this reason but somebody else might..
Just try taking the .html off the link like this, then I'm sure you'll get the error now.
URL yahoo = new URL("http://www.yahoo.com/sadjhasjd");
I know it's not what you want but that is all I can offer. It seems to only look for the main index.htm(l) or welcome.htm(l) files. Sorry thats as much as I can offer on this.

Similar Messages

  • How to get the Response Code when a URL is launched from Web Dynpro

    Hello Experts,
    I have a Web Dynpro Application in which in one of its views i have an IFrame UI element in which i will show a resource stored somewhere ..
    But before showing it i want to check if the resource actually exists. For this i have to check the HTTP Response code from Web Dynpro Application without setting it in the Iframe..
    I am using the following code to get the Response Code:
    try{
    URL url = new URL("Some Url");
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.connect();
    wdComponentAPI.getMessageManager().reportSuccess("Response code ="+connection.getResponseCode());
    }catch(Exception e){
    wdComponentAPI.getMessageManager().reportSuccess("Exception");
    Now the Problem is whatever response Code occurs 403 (for No Proper Authorization), 404 (for Resource not found) etc..
    i always get Response Code=  500 (which is for Internal Server Error) shown in the messgae i have printed.
    Please let me know the correct way of getting the Response Code from Web Dynpro.
    Also my resource is lying on a SAP Portal 6.4
    Best Regards
    Sundeep
    Edited by: Sundeep Sethi on Feb 18, 2008 9:07 AM
    Edited by: Sundeep Sethi on Feb 18, 2008 10:23 AM

    Hi,
      Check this code from /thread/5242768 [original link is broken] if it works.
    try{
    URL myurl = new URL("http://calendar.google.com");
    URLConnection connection = myurl.openConnection();
    if(connection instanceof HttpURLConnection) {
    HttpURLConnection httpConnection = (HttpURLConnection) connection;
    HttpURLConnection.setFollowRedirects(true);
    httpConnection.setRequestMethod("HEAD");
    httpConnection.connect();
    System.out.println("Response = "+httpConnection.getResponseCode());
    catch(Exception e) {
    // print exception
    Regards,
    Harini S

  • How can i get the source code from java concurrent program in R12

    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    Zulqarnain

    user570667 wrote:
    Hi 2 all,
    How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
    Regards,
    ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • I own acrobat 9 pro and had to re-download the program from a computer issue but when i get the serial code from the adobe website it give me serial code invalid error.  i am using copy and paste to prevent miss typing the code.

    i own acrobat 9 pro and had to re-download the program from a computer issue but when i get the serial code from the adobe website it give me serial code invalid error.  i am using copy and paste to prevent miss typing the code.

    Hi Lawrence,
    Please try the steps mentioned in the KB: https://helpx.adobe.com/creative-suite/kb/error-invalid-serial-number-acrobat.html
    Regards,
    Rave

  • How do I get the java code from a class file ?

    I want to know how to findout the java code from a .class file . Is there any utility or any way to get the java code from a .class file. If so , please let me know the step by step procedure .
    Thanks
    Shiva

    Check out Mocha (http://www.brouhaha.com/~eric/computers/mocha.html)
    It's free!

  • HT201328 I am trying to get the unlock code from ATT

       I am trying to get the unlock code from ATT for my Iphone 4S bought in an Apple store, and now they refused to give it, because it is reported as stolen.
    I have all the invoices and recepts, .
    How can I do to unlock the phone if they continue in their negative and hostile attitude???
    Thanks,
    Paul
    [email protected]

        hipichik Hello there. Let's get more specific information. What type of lock code are you referring to? And what are you looking to do with your phone?
    SheritaH_VZW
    Follow us on Twitter
    @VZWSupport

  • How can i get the tax code from Condition record number

    Hi all,
    i have the Condition record number from which i have to get the tax code as i looked inthe KNOP that Condition record number there but no tax code is maintained there.
    so is there any other way to find the tax code for particular Condition record number
    Regards
    suresh

    hi suresh,
    can u tell me the field name for condition record number and in which table it is stored.
    because i knew one condition number which is stored in table EKKO and the field name is
    KNUMV- Number of the document condition.
    from ekko take relevant details and look for  ekpo where u find the tax code
    filed name of the tax code id MWSKZ- Tax on sales/purchases code

  • "Wrong" content in response message from Sync HTTP receiver connection

    Hello,
    We're trying to set up a synchronous HTTP receiver connection in a BPM to send a PO to a business partner. This partner will then respond with a response message or an error message.
    Request : messagetype_request
    Response : messagetype_response
    Fault message: messagetype_fault
    Our problem is that a sync HTTP connection apparently does not support the fault messages and therefore the errormessage, based on the messagetype "messagetype_fault" is returned into the responsemessage with messagetype "messagetype_response". This means that we can not perform any manipulation on this message due to the wrong messagetype compared to the content.
    Using a switch in the BPM that checks on the existence of an X-path expression we have already splitted branches for the errorhandling and succesfull response handling.
    Does anyone have an idea how to change the errormessage that is stuck in the messagetype_repsonse  format ?
    Thanks in advance !

    Hi Stefan,
    Thanks for the answer, but this leaves me with the main question how I can change a certain message within a BPM from one messagetype to another. Normally a simple message mapping would do the job but the problem in this case is that the source message does not have the message structure that would be expected by the BPM due to the error message being received in the message that was reserved for the correct response.

  • HttpURLConnection , Response Code : 404 for HTTP method HEAD  302 for GET

    After establishing the connection For the URL : http://calendar.google.com/ the response code is different for different HTTP METHODS.
    For the method HEAD the response code is 404
    For the method GET the response code is 302
    Ideally according to W3 standards the header part for both methods should be same.
    www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    Unfortunately all the websites are not following the same standards.
    The above brings up an important issue.
    (i.e) soley depending on the HEAD method for checking the validity of the link may fail sometimes even if the link is
    valid.
    Please put up your comments and observations on this.
    Sample Code
    public static void main(String[] args) {
    try{
    URL myurl = new URL("http://calendar.google.com");
    URLConnection connection = myurl.openConnection();
    if(connection instanceof HttpURLConnection) {
    HttpURLConnection httpConnection = (HttpURLConnection) connection;
    HttpURLConnection.setFollowRedirects(true);
    httpConnection.setRequestMethod("HEAD");
    httpConnection.connect();
    System.out.println("Response = "+httpConnection.getResponseCode());
    catch(Exception e) {
    System.out.println(e);
    Edited by: rama.krishna on Dec 3, 2007 3:47 AM

    Iam not encountering any problem.It's just a discussion.

  • How to read the html code from a specific page

    is there a way that I can get the source code of a specific url and display that into a textarea with java?

    Sure. One thing you could do would be to have a servlet that fetches html from a given url and stores the html in a jsp bean. You can then use the data in this bean to populate the text area.

  • How do I get the return value from an executable?

    I'm running an external executable from dbms_scheduler but how do I get the exit code from the program run or any screen output?

    Hi,
    In the additional_info column of schedulerjob_run_details there should be something like
    job of type EXECUTABLE failed with exit code: Operation not permitted
    "Operation not permitted" is the error code (as translated by the errors header file for that platform).
    In releases 10.2 and up there may also be a line in the additional_info
    STANDARD_ERROR="Error text here"
    This gives the standard error messages output by the application. There is no way to get the standard output of the application.
    Hope this helps,
    Ravi.

  • Return HTTP Response Code from custom login module

    Hi,
    I´m trying to set an HTTP Response Code from a custom login module. Getting HTTP Headers works, so basically the approach is working.
    What I do is:
    HttpSetterCallback responseSetterCallback = new HttpSetterCallback();
    responseSetterCallback.setType(HttpSetterCallback.RESPONSE_CODE);
    responseSetterCallback.setValue("401");
    _callbackHandler.handle(new Callback[] );
    When executing on a J2EE 6.40 I get the following error:
    java.lang.IllegalArgumentException: hsc.getType()==8 not yet supportedhsc.getType()==8 not yet supported
    (with Type 8 standing for Response Code)
    It looks as if this feature has not been implemented yet (although been described in the SAP documentation). How can I fix this problem, is there any workaround to set the Response Code in another way?
    Thanks!
    Kind regards,
    Daniela

    Hi Daniela,
    sorry for the late reply - you may have resolved your problem now, but still wanted to follow up on it in case others experience the same.
    The support for this type in the callback is available from SP12 on. I guess you're using a lower SP. So, if you upgrade, you'll get the problem resolved (otherwise, I'm not aware of any workarounds.)
    Hope that helps!

  • How can i get the correct text from the url which has the mulitp-languages?

    hi, all
    i built a application and deployed it on sun application server 8.1. when i request a url which include some multi-languages (for example http://xxx.com/servlet?value=XXX. the 'XXX' may be simply chinese. ), i got the ??? instead of the correct text. how can i do it? in tomcat server, i can set the URIEncoding=GBK to get the correct code in server.xml. how can i do it in sun app server?
    thanks.

    Ok, it is unclear on what is happening here.
    Are you saying that when the webclient gets the data that it is not honoring the quote characters? Or the processing of the data buffer is causing issues?
    This is what I see the of your example text which is trying to be parse out:
    <a onmouseover="EnterContent('ToolTip','תווית על בגד: &rsquo;&rsquo;תן לאישה לכבס. זה תפקידה&rsquo;&rsquo;','<u><span style=color:#000099;>כתב: Spook בתאריך: 08.03.15 שעה: 22:11</span></u><br>מחאת טוויטר קמה בעקבות תוויות שוביניסטיות שהדפיסה חברת אופנה באינדונזיה לפיהן תפקיד הכביסה מוטל על האישה. החברה התנצלה אך כנראה רק עשתה רק יותר נזק לע...'); Activate();">";
    It appears to me that the  escapes `&rsquo;` does not have matching `&ldquo;` anywhere within the tooltip. So it appears that the page properly places left quotes in when processing the page, but the raw html has broken text.
    Hence a garbage in, garbage out situation.
    William Wegerson (www.OmegaCoder.Com)

  • Unable to get the response from dynamic partnerlink

    Hi
    I used dynamic partnerlink, in this i am able to invoke the services dynamcially but i am unable to get the response from the services which i had invoked dynamically. In my dynamic partnerlink wsdl i had included callback binding and call back service in the wsdl you can see them below
    <binding name="LoanServiceCallbackBinding" type="tns:LoanServiceCallback">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="onResult">
    <soap:operation soapAction="onResult" style="document"/>
    <input>
    <soap:header message="tns:RelatesToHeader" part="RelatesTo" use="literal" required="false"/>
    <soap:body use="literal"/>
    </input>
    </operation>
    </binding>
    <service name="LoanServiceCallbackService">
    <port name="LoanServiceCallbackPort" binding="tns:LoanServiceCallbackBinding">
    <soap:address location="http://openuri.org"/>
    </port>
    </service>
    please help me on this
    thanks
    Srikanth

    Hi, thanks for the input
    Actually My partnerLink had two messageTypes one for Input message request and the other for the Output message request and for the input message i had used the operation as initiate also for the output messsage type operation as result.For both of them binding is defined.
    With these am passing the values from myBPELl to the service which am nvoking dynamically but unable to capture the response the variables are local to myBPEL.

  • When I give the redeem code from the package I bought today from over an hour away, this is what i get and no forun seems to deal with it nor do I have days to chase adobe down.  Oops! This code doesn't seem to be active. Please contact the retailer you p

    When I give the redeem code from the package I bought today from over an hour away, this is what i get and no forun seems to deal with it nor do I have days to chase adobe down. Oops! This code doesn't seem to be active. Please contact the retailer you purchased the card from, or use a different code. For more information contact Customer Support and order by phone

    See if this helps:
    https://helpx.adobe.com/x-productkb/global/find-serial-number.html

Maybe you are looking for