I am constructing a post request and I would like to post it to a page
using asp code, i.e., I don't want to make a form and then press a
button. I have read that the third party component asphttp works for
this purpose, but my IHP doesn't provide this component.
Is there some way to simulate the asphttp component? I thought I
might be able to use the ServerXMLHTTP component, which my IHP does
provide, but I think that will only post well formed xml. Hmmm.
Anybody got any ideas.
FYI, I plan to construct the post request by converting the java code
below to asp. I am only going to user the part that constructs the
post request string. I don't think ASP can make output sockets or
input readers, but I could be wrong.
Thanks, Tom
Post Request construction code:
-construct using code (Java)
try {
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" +
URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" +
URLEncoder.encode("value2", "UTF-8");
// Create a socket to the host
String hostname = "hostname.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket socket = new Socket(addr, port);
// Send header
String path = "/servlet/SomeServlet";
BufferedWriter wr = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream(), "UTF8"));
wr.write("POST "+path+" HTTP/1.0\r\n");
wr.write("Content-Length: "+data.length()+"\r\n");
wr.write("Content-Type:
application/x-www-form-urlencoded\r\n");
wr.write("\r\n");
// Send data
wr.write(data);
wr.flush();
// Get response
BufferedReader rd = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
}
wr.close();
rd.close();
} catch (Exception e) {
}