Results 1 to 2 of 2
  1. #1
    higashij is offline Member
    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Default Problems writing to an outputstream

    Hi Everyone!

    I have a string that I'm trying to put onto an outputstream that connects to a servlet. My problem is I don't think I'm writing anything onto the outputstream since on the servlet side, my System.outs on my log file just show dashes.

    This is what I'm doing to write the string onto the outputstream:

    Java Code:
    URL url = new URL("My URL");
    
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");
    connection.setUseCaches(false);
    connection.setRequestProperty("Content-type","text/xml");
    connection.setRequestProperty("Connection", "Keep-Alive");
    
    OutputStream out = connection.getOutputStream();
    
    String test = "test";
    out.write(test.getBytes());
    out.flush();
    connection.connect();
    out.close();
    And this is the code on my servlet that reads the inputstream:

    Java Code:
    InputStream in = request.getInputStream();
    
    BufferedReader inStream = new BufferedReader(new InputStreamReader(in));
    
    String line;
    StringBuffer xmlStrBuf = new StringBuffer();
    
    while((line = inStream.readLine()) != null) {
              System.out.println(line);
              xmlStrBuf.append(line);
            }
    Thanks!!!!

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Java Code:
    OutputStream out = connection.getOutputStream();
    
    String test = "test";
    out.write(test.getBytes());
    out.flush();
    [B]connection.connect();  [/B] //<-------
    connect first before getting the stream.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Outputstream not streaming.
    By dantestein in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 08:36 AM
  2. source for OutputStream.writeObject()
    By xcallmejudasx in forum New To Java
    Replies: 5
    Last Post: 12-12-2008, 10:53 PM
  3. interrupting urlconnection's outputstream
    By zynasis in forum Networking
    Replies: 5
    Last Post: 10-02-2008, 01:49 AM
  4. Converting InputStream to OutputStream
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-11-2008, 11:13 PM
  5. HashMap to share OutputStream
    By gabriel in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •