Re: Convert .net xmlhttp code to vbs
- From: "Anthony Jones" <Ant@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 20:49:19 -0000
"cross" <cross@xxxxxxxxxx> wrote in message
news:eIxxEO2WHHA.4632@xxxxxxxxxxxxxxxxxxxxxxx
Can you please help me to finish converting the .net code below intoencoding.GetBytes(postdata);
vbscript?
My vbs function at the end works when posting to another asp file on the
same win server,
but I need to post the xml to a .jsp file on a unix box. The jsp file just
returns an internal server error. It crashes with a null pointer exception
when trying to read the request. Presumably because it is not in an ascii
byte array?
How do I do those parts?
If it is too complex, then let me know and I will use the .NET code as a
relay. I would just prefer to have it all in one file.
.NET CODE
=========
// create a web request and set the method of the request to POST
HttpWebRequest request = (HttpWebRequest)
HttpWebRequest.Create(requestLocation);
request.Method = "POST";
// encode the data and store the byte representation in an array
ASCIIEncoding encoding = new ASCIIEncoding();
string postdata="xml="+HttpUtility.UrlEncode(xmlDoc);
// string postdata="xml="+xmlDoc; byte[] requestData =
request.GetResponse();
// set the content type of the data being posted.
request.ContentType="application/x-www-form-urlencoded";
// set the content length of the string being posted
request.ContentLength = postdata.Length;
// Status.Text += "Submitting activity message";
Stream requestStream = request.GetRequestStream();
requestStream.Write(requestData,0,requestData.Length);
// flush out the data to the underlying stream and close it
requestStream.Flush();
requestStream.Close();
// retrieve the response from the web server
HttpWebResponse response = (HttpWebResponse)
StreamReader responseData = new
StreamReader(response.GetResponseStream());
err+= responseData.ReadToEnd();
MY VBS CODE
===========
Function iXMLPostSTX(STX_URL, POXMLData, ByRef XMLResp)
Dim oHttp
Set oHttp = Server.CreateObject ("MSXML2.ServerXMLHTTP")
Dim status
oHttp.open "POST", STX_URL
oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.setRequestHeader "Connection", "Keep-Alive"
oHttp.send POXMLData
status = oHttp.statusText
iLog("Status=" & status)
XMLResp = oHttp.responseText
End Function
It's unclear what the data type POXMLData is but I'll assume it's a string.
oHttp.send "xml=" & Server.URLEncode(POXMLData)
However, if you have control over the content of the JSP then why not simply
send the XML raw as an "text/xml" content type?
.
- References:
- Convert .net xmlhttp code to vbs
- From: cross
- Convert .net xmlhttp code to vbs
- Prev by Date: Re: reading a file that has null or blank field
- Next by Date: Re: reading a file that has null or blank field
- Previous by thread: Convert .net xmlhttp code to vbs
- Next by thread: Unexpected Next
- Index(es):
Relevant Pages
|