cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Request for --noheaders option

From: Patrick Lannigan <patrick_at_lannigan.org>
Date: Sun, 07 Dec 2003 18:49:34 -0500

Mayuresh,

As requested.

Here is the Java code to "throw XML" at a URL without any headers
whatsoever.

You call the program in the following format:

java xml_send <url> <input file name> <output file name>

e.g.

java xml_send https://yy.someurl.com/xml/rx.asp inqr4.xml resp5.xml

import java.net.*;
import java.io.*;
import java.util.*;
import javax.net.ssl.*;

import com.sun.net.ssl.internal.www.protocol.https.*;
import java.security.Security;

public class xml_send {

  public static void main(String[] args) throws Exception {

    if (args.length < 3) {
      System.out.println("Usage: java xml_send URL filename");
    }
    else {
      try {
// Add provider
         System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
         Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
              
        URL url = new URL(args[0]);
        String document = args[1];
        String response = args[2];
        FileReader fr = new FileReader(document);
        FileWriter fw = new FileWriter(response);
        char[] buffer = new char[1024*10];
        int bytes_read = 0;
        if ((bytes_read = fr.read(buffer)) != -1)
          {
            URLConnection urlc = (URLConnection) url.openConnection();
            urlc.setRequestProperty("Content-Type","text/xml");
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            PrintWriter pw = new PrintWriter(urlc.getOutputStream());

            // send xml to jsp
            pw.write(buffer, 0, bytes_read);
            pw.close();

            BufferedWriter out = new BufferedWriter( fw );
            BufferedReader in = new BufferedReader(new
InputStreamReader(urlc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
            {
                    out.write(inputLine);
                System.out.println(inputLine);
            }
            in.close();
            out.close();
            }
          }
          catch (Exception e) {
          e.printStackTrace();
          }
       }
    }
}

Mayuresh Kadu wrote:
>
> Patrick,
>
> a bit OT, but could i have a look at that java code ? :)
>
> - Mayuresh
>
> Patrick Lannigan said:
> > (my apologies to the administrator as I first posted this to
> > curl-users-admin by mistake)
> >
> > Thank you for inventing curl!
> >
> > I need to send XML to https://someurl.com/abc/xyz.asp
> >
> > The trouble is the site really isn't using HTTP protocol at all and
> > just expect the "XML" with no HTTP headers whatsoever (i.e. using the
> > -d option (to send the xml data) *without* sending the "POST" header -
> > or any other headers)!
> >
> > I got a friend to do the code in Java but I would much rather use
> > curl.exe command line tool to do this (because it's *so* well supported
> > by people like you).
> >
> > I realize that this may be "out of scope" but I've seen (a few) similar
> > requests from other people on the mailing list archives, in the past,
> > and thought it wouldn't hurt to ask. Also, the rise of "throwing XML"
> > at URL's is becoming more popular overall, and this would represent a
> > new use for curl.
> >
> > I realize that I could do a special compile myself - to create my own
> > version of curl - but I'm a blundering idiot when it comes to compiling
> > (especially on windows).
> >
> > I could donate a $100 or so dollars to "the cause" (and sorry if such a
> > little amount is offensive to anyone) if that helps.
> >
> > Thanks for listening.
> >
> > Patrick
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: IBM Linux Tutorials.
> > Become an expert in LINUX or just sharpen your skills. Sign up for
> > IBM's Free Linux Tutorials. Learn everything from the bash shell to
> > sys admin. Click now!
> > http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
Received on 2003-12-08