How to send a http request to a non java appln

I have one legacy web application running which can handle only http request . So I need to connect (using http request) and send my request and get the response, without opening that application in browser.
Any idea
1) How to connect to non - java appln from a java appln ?
2) How to use the Httprequest without displaying the page using browser?

You can try one of three routes:
Open a socket and write the HTTP request and parse the HTTP response yourself
Use java.net.URLConnection
Use Jakarta Common's HttpClient at jakarta.apache.org- Saish

Similar Messages

  • How to send a HTTP request to servlet in java application

    I'm new in Java. I need to send a HTTP request with parameters to servlet in a java aplication. Here is my code. It can be compiled but always threw an exceptions when I ran it. Can anyone help?
    package coreservlets;
    import java.io.*;
    import java.net.*;
    public class PostHTTP
         public static void main(String args[])
              throws IOException, UnknownHostException {
              try
              // URL and servlet
                   URL myURL = new URL("http://pc076/servlet/coreservlets.OffHold");
                   URLConnection c = myURL.openConnection();
                   c.setUseCaches(false);
                   c.setDoOutput(true);
                   ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
                   PrintWriter out = new PrintWriter(byteStream, true);
    //parameters
                   String postData = "REASON_CODE=3B&RSPCODE=JSmith&CASENUM=NA795401&REPLY=123&SOURCE=XYZ&REPLYLINK=http://pc076/servlet/coreservlets.ShowParameters";
                   out.print(postData);
                   out.flush();
                   String lengthString = String.valueOf(byteStream.size());
                   c.setRequestProperty("Content-Length", lengthString);
                   c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                   byteStream.writeTo(c.getOutputStream());
                   BufferedReader in =     new BufferedReader(new InputStreamReader
                                                 (c.getInputStream()));
                   String line;
                   //String linefeed = "\n";
                   //resultsArea.setText("");
                   while((line = in.readLine()) != null) {
                        System.out.println(line);
                        //resultsArea.append(linefeed);
              catch(IOException ioe) {
              // Print debug info in Java Console
              System.out.println("IOException: " + ioe);

    here are some updates to your code I haven't tested it running
    post again if you still have trouble
    URL myURL = new URL("http://pc076/servlet/coreservlets.OffHold");
    HttpURLConnection c = (HttpURLConnection)myURL.openConnection();
    c.setDoInput(true);
    c.setDoOutput(true);
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
    String lengthString = String.valueOf(byteStream.size());
    c.setRequestProperty("Content-Length", lengthString);
    c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    PrintWriter out = new PrintWriter(byteStream, true);
    //parameters
    String postData = "REASON_CODE=3B&RSPCODE=JSmith&CASENUM=NA795401&REPLY=123&SOURCE=XYZ&REPLYLINK=http://pc076/servlet/coreservlets.ShowParameters";
    out.print(postData);
    out.flush();
    byteStream.writeTo(c.getOutputStream());
    // connect
    c.connect();
    BufferedReader in = new BufferedReader(new InputStreamReader
    (c.getInputStream()));
    String line;
    while((line = in.readLine()) != null)
        System.out.println(line);

  • How to send a https request using jsf

    hi
    Can anybody tell a sample how to send a https request using JSF ...
    thanks

    Prefix the request URI with the https protocol.
    The answer is too easy and straightforward that I guess that you mean something else. If you just want to know how to configure an SSL environment for your own webapplication, refer to the Java EE tutorial chapter 28: http://java.sun.com/javaee/5/docs/tutorial/doc/

  • How to pass a HTTP request from a simple java class

    Is it possible to pass an HTTP request from a simple java class.if yes how?

    Is it possible to pass an HTTP request from a simple
    java class.if yes how?If you're talking about creating a HttpRequest object and passing it to a servlet, that would be a red flag to me that your design is flawed. You shouldn't have to do that - the application server (Tomcat, Weblogic, etc) should be the only thing that has to worry about creating that kind of object and passing it to you.

  • How to send a http-request from abap?

    I want to send a xml file through a http-request ,what should i do?

    Welcome to SDN
    you can use cl_http_client class to do that. search the abap general forum with key word cl_http_client and you will find lot of examples.
    Regards
    Raja

  • How to send POST HTTP Request through PI .

    Hi ,
    I am trying to send a XML mesage at HTTP server from SAP PI 7.1 .
    but not able to , reason is HTTP guy telling me is that ,i am sending a get request through SAP PI 7.1 and it should be POST.
    Where to change this this thing , so that only post request should go.
    There is one more thing , i am facing following request only in Quality . In Development request is going as Post and every thing running fine ...
    Regards
    PS

    It was always HTTP from our end , some config was missing at HTTP guys end , which solve the problem ..
    So there was no issue at PI end.

  • How does Flash send outgoing HTTP request to server?

    Hello everyone,
    I would like to know how Flash sends outgoing HTTP requests.
    I would like to know when from the inside of a Flash SWF file
    request for another SWF or FLV file is made; how the Flash sends
    this request to server.
    Thank you very much and have a great day,
    Khoramdin

    Hello everyone,
    I would like to know how Flash sends outgoing HTTP requests.
    I would like to know when from the inside of a Flash SWF file
    request for another SWF or FLV file is made; how the Flash sends
    this request to server.
    Thank you very much and have a great day,
    Khoramdin

  • Sending an http request

    Hi,
    I want to send an http request with a string(this is an xml string)which will give me a response which contains an xml string again.Can anybody tell me how can i do it in java.Any sample code will be a great help
    thanks in advance.

    This is a example, hope to be useful for you.
    String xml = "<?xml version="1.0" encoding="GBK"?>"
    + "<operation_info>"
    + "<request_code>11000008</request_code>"
    + "<id_number>13148709165</id_number>"
    + "<id_type>2</id_type>"
    + "<session_id>100000002226</session_id>"
    + "<device_uid>100000000005</device_uid>"
    + "</operation_info>";
    String http_url = "http://127.0.0.1:8888/protocol";
    URL sendUrl = new URL(http_url);
    URLConnection urlCon = sendUrl.openConnection();
    urlCon.setDoOutput(true);
    urlCon.setDoInput(true);
    HttpURLConnection httpConnection = (HttpURLConnection) urlCon;
    httpConnection.setRequestMethod("POST");
    httpConnection.setRequestProperty("Content-Type", "text/xml;charset=GBK");
    httpConnection.setRequestProperty("Content-Length", Integer.toString(xml.length()));
    PrintStream ps=null;
    try {
    ps = new PrintStream(httpConnection.getOutputStream());
    }catch(java.net.ConnectException e){
    e.printStackTrace();
    return "error"; ;
    xml = URLEncoder.encode(xml);
    try{
    ps.write(xml.getBytes());
    ps.flush();
    //get response stream
    String str = httpConnection.getResponseMessage();
    InputStream is = httpConnection.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    str = "";
    StringBuffer sb = new StringBuffer();
    while ((str = br.readLine())!=null) {
    sb.append(str);
    is.close();
    return sb.toString();
    }catch(Exception e){
    e.printStackTrace();
    return "error"; //exception
    }

  • HT4314 How to send a game request to my friends

    How to send a game request to my friends

    Hi,
    How about your issue now? Is it fixed?
    I think you will get progessional support from other network related forum. Because VC++ forum aims to discuss and ask questions about the Visual C++ IDE, libraries, samples, tools, setup, and Windows programming using MFC and ATL.
    Hope you can understand.
    May
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to send a multicast request to 239.255.255.253, seeking an SLP Directory Agent (DA)?

    Hi,
    How to send a multicast request to 239.255.255.253, seeking an SLP Directory Agent (DA) in C++?
    Thanks in advance.

    Hi,
    How about your issue now? Is it fixed?
    I think you will get progessional support from other network related forum. Because VC++ forum aims to discuss and ask questions about the Visual C++ IDE, libraries, samples, tools, setup, and Windows programming using MFC and ATL.
    Hope you can understand.
    May
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to send a Meeting Request to Exchange/Outlook using JavaMail

    Hi,
    Can any body help me "How to send a Meeting Request to Exchange/Outlook using JavaMail" which will be added to the calendar items.
    If possible, please provide me with the sample code. Please send the sample code to the following mail id: "[email protected]".
    Thanks in advance,
    Ashok.

    I don't have a homework problem. I have a real business need for this, but haven't been able to get my code to work yet. There are at least two references out there, but either the sample code hasn't been posted or I don't know where to look. Can you help?
    Thanks.

  • How to transfer the http request from applet to servlet/jsp

    I use the JTree component to create a navigation of a website,but i don't
    know how to connect the tree's nodes with the jsp/servlet.
    I mean how to transfer the http request from the applet to a jsp.
    I use the "<frameset>" mark which will divide the web browse into 2 blocks.
    The left side is Applet,and the right side is the linked jsp page.
    what I say is as the weblogic console layout.
    who can help me!!!
    Thank You!

    I use the JTree component to create a navigation of a website,but i don't
    know how to connect the tree's nodes with the jsp/servlet.
    I mean how to transfer the http request from the applet to a jsp.
    I use the "<frameset>" mark which will divide the web browse into 2 blocks.
    The left side is Applet,and the right side is the linked jsp page.
    what I say is as the weblogic console layout.
    who can help me!!!
    Thank You!

  • Is it possible to send several http requests at the same time?

    hi:
    is it possible to send several http requests at the same time in j2me application, or it's device specific.
    It's ok in my NOKIA SYMBIAN C++ application.
    regards
    Message was edited by:
    danielwang

    Is it possible to have 2 threads running at the same
    time at different times eg 1 repeats every 20
    miliseconds and the other 40 for example. Yes.
    http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

  • How to send data to bam data object through java code

    how to send data to bam data object through java code

    I've made a suggestion in other thread: https://forums.oracle.com/thread/2560276
    You can invoke BAM Webservices (Using Oracle BAM Web Services) or use JMS integration using Enterprise Message Sources (http://docs.oracle.com/cd/E17904_01/integration.1111/e10224/bam_ent_msg_sources.htm)
    Regards
    Luis Fernando Heckler

  • How to send sms to mobile from tomcatserver using java code?

    Hi,
    Could you please let me know that,
    How to send sms to mobile from tomcatserver using java code? Please provide the code snippet.
    Thanks in advance.

    Yes, but something needs to send that message. You can't just take an arbitrary computer and send an SMS, it does not have the hardware to do that.
    So either you have a mobile through which you do that or more likely - you use some sort of online service to do it. Whatever choice you make will determine what code you will have to write to get it done. Nobody is going to deliver the code to you, that's your job. It is also your job to figure out what service you are going to use.

Maybe you are looking for

  • HT201328 how can i tell if my iphone 4 is unlocked?

    How can i tell if my iphone 4 unlock worked?

  • Why can't you make a sap.m.Dialog be modal?

    We have decided to use mainly mobile components and I am wondering why the sap.m.Dialog component doesn't have a setModal method to make it modal or not. Is modality not something that a mobile component needs? Thanks!

  • Oracle gateway for MS sql server 2005

    Is Oracle 9i Gateway for MS SQL Server compatible with SQL 2005? If not what are the other options?

  • Solid State Hard Drive Issues.....

    Hello. I had a Sattelite P-500 built by Toshiba last spring & it's beginning to give me trouble. It is a dual hard drive model, one 60 gig solid state & a 500 gig storage drive. My problem is that all but less than 1 gig is used up on the solid state

  • Font rendering problem... (FLash BUG)

    Hi all, I have Flash instaled on two machines and both of them are having a problem when rendring flash text. All text on flash appears like the image bellow. And When I export to SWF the text stays the same. The font I'm using is Myriad Pro I'm runn