Https protocol based URL reading Program

This is the simple code to read through a java program from a simple http based procot URL
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
     URL yahoo = new URL("http://mail.yahoo.com/");
     BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yahoo.openStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null)
     System.out.println(inputLine);
     in.close();
But if i use the url https://mail.yahoo.com/ instead of http://mail.yahoo.com/ then i have an exception given below
Exception in thread "main" java.io.IOException: HTTPS hostname wrong: should be
<mail.yahoo.com>
at sun.net.www.protocol.https.HttpsClient.b(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA12275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(DashoA12275)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:626)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Dash
oA12275)
at java.net.URL.openStream(URL.java:913)
at URLReader.main(URLReader.java:7)
Now i want this program based on https to run. SO can anybody help me running the same program by using https? Or can anybody give me the code to run a url based on https protocol?

Here is a code which works for me.
import java.net.*;
import java.io.*;
public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
        URL myurl = new URL("https://my.app.com/");
        URLConnection yc = myurl.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                yc.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
}Output:
<html><head>
<script>location.replace("/my/app?action=homeActionId");</script>
</head></html>

Similar Messages

  • URL reading program

    Hello, with this program I am trying to get input (the content) from one or more urls and then print that content to a txt file or html file.
    This is my code so far, please could you advise or change the code so that it carries out the function I require.
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class URLReader
         public void process (String[] argStrings) throws Exception
              URL url;
              String fileName = argStrings[0];
              String contents = null;
              url = new URL(argStrings[0]);
              System.out.println();
              System.out.println("Conatenated contents of selected pages:");
              System.out.println();
              PrintStream output = new PrintStream("NewFile.txt");
              for (int index = 0; index < argStrings.length; index++)
                   Scanner sc = new Scanner(new File(argStrings[index]));
                   contents = sc.nextLine();
                System.out.println(contents);
                   output.println(contents);
                   sc.close();
    }Thanks anyone

    Thanks, it was not the exact code as I want to be able to specify the url 's on the command line but anyway that helped alot.
    Please check out my code and see whats wrong as it compiles ok but gives an error in dos.
    cheers
    // Import necessary classes
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class URLReader
         public void process (String[] argStrings) throws Exception
              // Declaring necessary variables
              String contents = null;
              URL url = new URL(argStrings[0]);
              BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
              // Asks user to input URL's to be concatenated
              System.out.println();
              System.out.println("Concatenated contents of selected pages:");
              System.out.println();
              // Opens file
              PrintStream output = new PrintStream("NewFile.txt");
              // Loop where all URL's content is read and then written to NewFile.txt
              for (int index = 0; index < argStrings.length; index++)
                   // New instance of scanner
                   Scanner sc = new Scanner(new File(argStrings[index]));
                   contents = sc.nextLine();
                System.out.println(contents);
                   output.println(contents);
                   sc.close();
    }

  • Publish live stream to FMS on HTTP protocol

    Hi,
    I want to use customised encoder to publish live steams to a FMS4.5 server?
    Is it possible to connect encoder and FMS4.5 server on HTTP protocol?
    i read in other articles FMLE can connect to FMS on RTMP protocol.
    Very urgent.
    thanks,
    Pooja Jain

    Hi
    I think this would be useful to you.
    http://help.adobe.com/en_US/flashmediaserver/devguide/WSd391de4d9c7bd609-52e437a812a3725df a0-8000.html#WSd391de4d9c7bd609-52e437a812a3725dfa0-7ff5

  • Java Program to run an https based url

    This is the simple code to read through a java program from a simple http based procot URL
    import java.net.*;
    import java.io.*;
    public class URLReader {
    public static void main(String[] args) throws Exception {
         URL yahoo = new URL("http://mail.yahoo.com/");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        yahoo.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    But if i use the url https://mail.yahoo.com/ instead of http://mail.yahoo.com/ then i have an exception given below
    Exception in thread "main" java.io.IOException: HTTPS hostname wrong: should be
    <mail.yahoo.com>
    at sun.net.www.protocol.https.HttpsClient.b(DashoA12275)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA12275)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
    (DashoA12275)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:626)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Dash
    oA12275)
    at java.net.URL.openStream(URL.java:913)
    at URLReader.main(URLReader.java:7)
    Now i want this program based on https to run. SO can anybody help me running the same program by using https? Or can anybody give me the code to run a url based on https protocol?

    Same as http://forum.java.sun.com/thread.jspa?threadID=677398&tstart=0 . Check reply on the other post.

  • Help needed to start HTTP Protocol with timeout

    I am looking for information to point me in the right direction. I would like to create a class that would implement the HTTP protocol and would allow the user to specify a timeout if unable to connect to the server. I have used the URL and HttpURLConnection classes before, but have not used any of the other classes in the java.net package. I am just trying to create an app that will download a file from a specified URL. Something that I could use in the future and something to get more programming experience using the java.net package.
    Could you tell me:
    1) Which classes I would need to use to help implement a timeout
    2) Where I can find an example or other information on how to implement the HTTP protocol with the class from question 1 above.
    TIA for any information

    That would definately reduce the coding time but would
    do little to help with my understanding of classes in
    the java.net package or to gather a better
    understanding of the HTTP protocol. :-)
    That said, I am currently downloading the 1.5 beta to
    see what they have done.If it's just an academic thing to re-invent the wheel (code) that deals with the HTTP protocol, then go right ahead (ok, you don't need my permission).

  • Upload using HTTP protocol

    my requirement is to upload/tranfer a file to remote server(LAN/WAN) using http protocol.
    my application is not a web based application.
    if anybody knows how to do it, pls. let me know.
    thanks and regards
    Savitha

    You can use an URLConnection, but you need to cast it the HttpURLConnection in order to set the "method". The "official" method which ought to work for uploads is the "PUT" method, but it's not often used and, as a result, not all web proxies handle it. You may find POST is safer, even if your data isn't formatted as POST expects.
    It goes something like (from memory)
    URL url = new URL( ..... );
    HttpURLConnection con = (HttpURLConection)url.openConnection();
    con.setMethod("PUT");
    con.addHeader("Content-length", fileLength);
    con.addHeader("Content-type", mimeType);
    con.setDoOutput(true);
    OutputStream out = con.getOutputStream();
    ...Be warned though: Web systems do not expect very large uploads. Web proxies, in particular, can often cause a lot of grief if you are trying to upload anything about a megabyte or two in one message.
    It's important to set the Content-Length correctly to the size of the body data, since otherwise the system doesn't know when you've finished sending.

  • HTTP Protocol caused Duplicate Records

    Hello,
    Out company has just developed a j2me program for sales personal to place order from mobile phone. The program is developed using netbeans 6. The connection to the the server is using http protocol via gprs or 3G.
    There is a problem that we face; sometimes we there are duplicate entries from the one mobile request. For example, A sales personal placed an order and press the send button to the server.. The server incoming log sometimes will have multiple request from this this request..
    public void send()throws IOException
    //mainS = null;
    Days = "";
    if (mainS == null){
    getAlert1().setString("Invalid Input lala");
    throw new IOException("Invalid Input lala");
    String onum = getonum();
    StringBuffer b = new StringBuffer();
    String url = server + "?act=i&unm=" + uname + "&upw=" + upw + "&icode="+Icode+"&onum="+onum +"&dd="+ getDates() + "&num=" + mainS;
    System.out.println(url);
    try{
    //Connect to the server
    HttpConnection hc = (HttpConnection) Connector.open(url);
    //Authentication
    System.out.println(hc.getResponseCode());
    if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
    InputStream is = hc.openDataInputStream();
    int ch;
    while((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println(b.toString().trim());
    returnS = b.toString().trim();
    is.close();
    }else{
    getAlert1().setString("No respon from server.");
    hc.close();
    throw new IOException("No respon from server.");
    hc.close();
    }catch(Exception ex){
    getAlert1().setString(ex.getMessage());
    throw new IOException(ex.getMessage());
    Please help.

    yhkok wrote:
    Hi.
    Thank you for your reply. I think the problem caused by user to send multiple times should not be happened. Because when a user press "SEND" to submit the request, the can't press anything while waiting for the confirmation from the server. Perhaps the second issue cause the problem.. can you tell me more in detail how can I solve this problem.. or how can I check if the program send multiple time. This happens especially during heavily transactions or a lot of users send in together in a short period. Can It cause by while waiting for the server to reply.. the user end "time-out" and send the form again ? We are using Nokia 2630 mobilephone which loaded with S40 5th edition..
    Regards.
    KokI carefully said the user OR the user browser (whatever that may be) is re-submitting the form.
    Who cares why? It doesn't matter why. It (or someone) just is.

  • How to do I  tomcat6 to accept https protocol?

    Hi friends,
    I was trying to configure my local tomcat6 in windows XP for https protocol(SSL).
    My tomcat runs when I put http://localhost:8888 in browser address bar.
    But, when i try to run https://localhost/8443 it gives me the following error:
    An error occurred during a connection to localhost:8443.
    SSL received a record that exceeded the maximum permissible length.
    +(Error code: ssl_error_rx_record_too_long)+
    I have followed the following steps:
    1> c:\>keytool -genkey -alias tomcat -keyalg RSA
    created the .keystore file
    placed the .keystore file in c:\tomcat6\ folder
    2> edited c:\tomcat6\conf\server.xml file
    uncommented connector entry for ssl and added two more attributes: one for .keystore location and anothet for its password
         <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    keystoreFile="C:\tomcat6\.keystore"
                        keystorePass="mypassword"
    />
    3> changed main connector entry to
    <Connector port="8888" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />
    saved c:\tomcat6\conf\server.xml file.
    4> Stopped Tomcat service. Started tomcat service.
    5> tried url : https://localhost:8443
    Please help me to configure ssl in tomcat6.
    hope some good response.
    thx.
    --Sujoy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Try a Tomcat forum. This is a Java JSSE programming forum. Locking the thread.

  • How to set up and test the Basic Authentication for HTTP protocol

    Hi,
    I tried configuring the password based Basic Authentication for sending xml document using ebMS - HTTP protocol. I set username and password while configuring the transport server for both trading partners. I want to know, is that sufficient for basic authenticaton. When I open the URI http://localhost:7778/b2b/transportServlet, it is not asking any authentication (username/password). Please note that I have not used SSL certificate. Anyone please help me out to configure Basic authentication.

    Hi Ramesh,
    Thanks for ur response. Could you please tell me where to set the Additional Transport header : authtype-basic#realm=myRealm(in which property file). In enqueue code, I could see the following attributes
    queue
    msgID
    replyToMsgID
    from
    to
    eventName
    doctypeName
    doctypeRevision
    msgType
    payload
    attachment
    subscriber
    Is it possible to set username/password in the enqueue attributes?
    Do i need to add username/password and Transport header in the input XML and defined that elements in xsd?

  • Proxy receiver channel with HTTP destination or URL address?

    Hi Experts,
         I have a scenario as below:
         (Webservice Client)SOAP --> PI --> PROXY(SAP ECC).
         A webservice client calls PI using SOAP. PI then sends the request to SAP ECC using PROXY.
        I am using AAE. Therefore I have ICO.
        In the receiver PROXY channel I have given:
       ADAPTER TYPE: SOAP
       Transport Protocol: HTTP
       Message Protocol: XI3.0.
       Under connection parameters:
       Addressing Type dropdown as 2 entries HTTP destination and URL address.
       In what cases i should use HTTP destination and URL address respectively?
       Which option is preferred?
       Do they work same or differently? How?   
       When I select HTTP destination where should I create the corresponding RFC destination? In PI ABAP stack using SM59 or PI NWA?
       If this HTTP destination is created in PI ABAP stack using SM59 then what type it should be? H? or G? 
    Thanks
    Gopal

    Hi Gopal,
    In creating XI receiver communication channel, you have 2 options for Addressing Type:
    1. URL Address - no need to create RFC destination. You just have to specify the XI receiver host name, HTTP port, path (/sap/xi/engine?type=receiver), Authentication data (logon details for SAP Client number of the PI system).
    2. HTTP Destination - create RFC destination in SXMB_ADM and specify the RFC destination name in your receiver communication channel.
    For SAP documentation, see this link:
    http://help.sap.com/saphelp_nwpi711/helpdata/en/f4/0a1640a991c742e10000000a1550b0/content.htm?frameset=/en/e1/091640a991c742e10000000a1550b0/frameset.htm&current_toc=/en/43/96cbccb9335b77e10000000a11466f/plain.htm&node_id=5
    Regards,
    Naveen.

  • Accessing seured website using java URL/Socket programming

    Hi,
    I am working on an intranet search engine using java URL and Authenticator class. This is a secured web-site using SSL in http server. I am not able to access the password protected pages. Following is the code:
    URL url = new URL("https://*************");
    URLConnection connection = url.openConnection();
    PasswordAuthentication pa = Authenticator.requestPasswordAuthentication( InetAddress.getByName(connection.getURL().getHost()),
    connection.getURL().getPort(), connection.getURL().getProtocol(), null, "Basic");
    StringBuffer buf = new StringBuffer("*****************");
    buf.append(":");
    buf.append("************");
    String encoded = new sun.misc.BASE64Encoder().encode(buf.toString().getBytes());
    connection.setRequestProperty ("Authorization", "Basic" + encoded);
    InputStream content = (InputStream)connection.getInputStream();
    BufferedReader in = new BufferedReader (new InputStreamReader (content));
    String line;
    while ((line = in.readLine()) != null) {
    System.out.println(line);
    Let me know if there is any other alternative
    tnx,
    Biswajit Biswal

    Below is my first test program. I first take the home page of a website (this can be automated later) and save it to "myTest.html". Then I try to see if this page contains the keywords that a company website often has.
    Could you give your opinion on this approach?
    If this approach is fine, then any idea about the keywords to select a company website from other sites is welcome.
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    public class MyTest {
          * @param args
          * @throws IOException
         public static void main(String[] args) throws IOException {
              InputStream in = MyTest.class.getResourceAsStream("/myTest.html");
              Reader reader = new InputStreamReader(in, "UTF-8");
              BufferedReader bufferedReader = new BufferedReader(reader);
              String line;
              while ((line = bufferedReader.readLine()) != null) {
                   line=line.toLowerCase();
                   if (line.contains("contact us")) {
                        System.out.println("contact us: line = "+line);
                   if (line.contains("career")) {
                        System.out.println("career: line = "+line);
                   if (line.contains("company")) {
                        System.out.println("company: line = "+line);
                   if (line.contains("about us")) {
                        System.out.println("about us: line = "+line);
                   if (line.contains("product")) {
                        System.out.println("product: line = "+line);
              bufferedReader.close();
              reader.close();
    }

  • How to register non-wsdl based URL in OEG

    How do we register a non-wsdl based URL endpoint in OEG? We had no problem registering a simple WSDL based endpoint on an OEG server. However we cannot find documentation on how to secure/register a RESTful or JSON – URL based service (SOAP, XML over HTTP type service).
    Does this functionality exist? Or are there best practices on what to do with OEG for these types of services?
    Our use case looks like:
    Akamai - - > OEG - -> OSB (WSDL, RESTful, JSON type web services) - -> .Net service (WSDL, RESTful, JSON type web services)

    In case of REST and other non-WSDL type services, there is no SOAP/WSDL based web service like registration process, you'd use OEG as the proxy. You can receive REST based requests at OEG, retrieve parameters (there are convenience filters available for retrieval of attribute values and other types of REST related functions in OEG, as part of the Policy library, "Extract REST Request Attribute", "Validate REST filter", "Create REST Request" etc. - search for REST at the top using Policy Studio, drag it on to canvas and click help for docs on these filters) and do the routing to actual REST end point services. You have the option to receive and use the SOAP message as a basis of generation of the REST url.
    REST to SOAP - http://www.soatothecloud.com/2008/11/how-to-convert-from-rest-to-soap.html
    SOAP to REST - http://markoneill.sys-con.com/node/1989916
    On use with JSON: you can convert XML to JSON on the outbound side to serve mobile clients etc. using script based(standard XSLT) conversions at the gateway. Conversions to Java using google gson library is also an option.
    To register a REST service, simply map the path (e.g. "/MyRESTService") to the policy you're using to process the REST request.
    Let's say you want to simply route a REST request through OEG (e.g. - to OSB). You would create a policy (right-click on "Policies" and add it). Drag in a "Static Router" filter and place in it the hostname and port of the host you want to route to (e.g. - to OSB). Then right-click on it and choose "Set as start" so that it is the first thing which is processed for this REST request. Then drag in a "Connection" filter, and chain it (using a green arrow) after the Static Router filter. The "Connection" filter actually makes the connection to the backend host.
    Now, map the path (using "Add Relative Path") to the service so that if a REST request to "/MyRESTService" or "/MyRESTService/something" comes into OEG, it is routed on to the backend host.
    Deploy your policy (using F6 or the "deploy" button on the Policy Studio toolbar). Then send in your REST request.
    There is actually already a simple REST service setup on OEG, called "healthcheck". If you point a browser to http://<OEG_IP_ADDRESS:8080/healthcheck" then this is run.
    If the backend REST service returns JSON, the response JSON will simply be sent back through OEG.

  • Using https protocol thru Oracle Developer 6.0

    Hi ,
    I would like to know if it is possible to use https protocol from Oracle Developer 6.0.
    we have used http protocol when using
    Show_Document() and it works fine. But when we try to use https (which our application requires - secure mode)then we get the following error:
    FRM-99999 Invalid URL sent to browser with target_BLANK.
    Full Details: unknown protocol:https
    We would appreciate any help on this problem.
    Are there any patches which would enable the use of this protocol??
    Thanks,
    Sanjay Sinha
    email:[email protected]
    null

    There are other services that may cause you trouble.
    I have had to turn off SMTP and DHCP services in the past.

  • HTTP PROTOCOL used in XI by default

    Hi All,
    I exported a wsdl file from XI and I want to use that wsdl to invoke the service in XI.
    I am using xml spy to test that wsdl.When I run it, it prompts me to enter user id & password & i do the same. The service gets executed.But now i am writing my own client program in axis..so how should i set authentication information.Do i need to set something in the wsdl in XI so that i will be able to set the authentication info.
    Can you tell me what is the default http protocol used by XI??
    Thanks,
    Archana

    HI,
    You have to enter the User,pwd.
    See this link also.
    /people/siva.maranani/blog/2005/03/01/testing-xi-exposed-web-services
    Regards
    Chilla..

  • HTTP protocol webmail

    I just signed up for DSL with Qwest and am buying a new 20" iMac. (I curently use a 1999 iMac 333 with dialup.) To get a low cost DSL ($30/ month) I have my ISP as MSN Premium. I know I need HTTP protocol for email and have read the achives to try to figure out what will work regarding web based email and my new iMac without it being a total pain in the butt.
    Do I need the HTTP mail plugin to use hotmail, gmail, yahoo, etc.?
    Would webmailer also be useful when using web based email with the iMac?
    What web based email have others used painlessly with OS 10.4?
    Thanks!
    20"iMac   Mac OS X (10.4.8)  

    Do I need the HTTP mail plugin to use hotmail, gmail, yahoo, etc.?
    The HttpMail plugin is only for Hotmail. It allows you to receive and send Hotmail through the Mail.app but apparently only works for older Hotmail accounts.
    Gmail offers free POP service (to work with Mail and other email client applications). Just follow the instructions here:
    http://mail.google.com/support/bin/answer.py?answer=13275
    Yahoo and other services that don't offer POP access, can sometimes be added to Mail.app with MacFreePOPs. I have used it for Yahoo mail before but, honestly, it was less of a hassle for me just going through Safari.

Maybe you are looking for

  • DIFFERENT ACCOUNTS DIFFERENT PROFILES

    I HAVE TWO ACCOUNTS IN  A BB 8310 WORKING RIGHT. I WANT CONFIGURE DIFFERENT TONES FOR MESSAGES RECEIVED ON EVERY ACCOUNT. WHEN I AM IN "PROFILES", IT SHOWS THE TWO ACCOUNTS: ONE BES AND ONE BIS I TRY CONFIGURE THE BES WITH A TYPE OF TONE AND THE BIS

  • With new ios7 i can no longer download games

    Hello I updated to ios7 and now i have only trouble. I can no longer download or up date games. If i get emails with a link, i can no longer open the link to a website.....i could go on and on.....but my biggest problem is, that i cant download any g

  • BLOB column -- no preview for jpg file

    Hi, I'm trying to create something close to the sample application with some other products. I have a table with BLOB column for the products jpg files. However, I have encountered the following challenge: the preview is not working. http://i39.tinyp

  • Best method for keeping iMovie projects long term?

    I read through 30 pages of posts as I think this is a pretty basic question, but didn't see it directly addressed, so please forgive me... Some of my movies are mammoth in size (as much as 30GB for 1 movie), which I've learned are due to iMovie handi

  • Why doesn't elements 12 have 64 bit support for PC users?

    Why doesn't elements 12 have 64 bit support for PC users? Most PC's these days are shipped with far more than 2GB of RAM. This move seems very limiting to those with high demands for RAM. Image sizes are only getting larger meaning more RAM needed fo