I am trying to a pass an xml file to a web server with http POST. Could someone provide me an example of this please. Below is what I have got so far. It connects to the webserver, but does not issue the correct POST informaton.
=========================================================
import java.net.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.*;
public class WebserverConnect {
private static
String defaultServer
= "http://myipaddress:myport/";
public static void main(String[] args) {
/* if (args.length == 0) {
System.out.println(
"Usage:
java FibonacciXMLRPCClient index serverURL");
return;
}
String index = args[0];
String server;
if (args.length <= 1) server = defaultServer;
else server = args[1]; */
String server;
String index = "0";
server = defaultServer;
ArrayList fileList;
try {
URL u = new URL(server);
URLConnection uc = u.openConnection();
HttpURLConnection connection = (HttpURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
OutputStream out = connection.getOutputStream();
OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
wout.write("<request name=\"ValidateCustomer\" key=\"[eStoreFr]\" password=\"estore\" company=01>");
wout.write("<CustomerNumber>C102</CustomerNumber>");
wout.write("</request>");
wout.flush();
out.close();
InputStream in = connection.getInputStream();
int c;
while ((c = in.read()) != -1) System.out.write(c);
System.out.println();
in.close();
out.close();
connection.disconnect();
}
catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
} // end main
}