Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HttpWebRequest in VB6 2

Status
Not open for further replies.

kennedymr2

Programmer
May 23, 2001
594
AU
I have some sample code as below, which i need to emulate in vb6
-----------------------
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(" httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-
byte[] bytePostData = Encoding.UTF8.GetBytes(GetPostData());
httpRequest.ContentLength = bytePostData.Length;

using (Stream datastream = httpRequest.GetRequestStream())
{
datastream.Write(bytePostData, 0, bytePostData.Length);
datastream.Close();
}

HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();

string responseString = "";
using (Stream dataStream = httpResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
responseString = reader.ReadToEnd();
reader.Close();
dataStream.Close();
}

Console.WriteLine(responseString);
}

private static string GetPostData()
{
StringBuilder sUrl = new StringBuilder();

sUrl.AppendFormat("u={0}&p={1}&method={2}", 5XXXXXX, XXXX, "Method1");
sUrl.Append("&data=xxxxxxxxxx" }]}");


return sUrl.ToString();
}
}
}



??????????? How do i perform this function in vb6


Really appreciate some advice

Regards Kennedymr2
 
Untested, given I don't have access to a relevant web service and also the apparant redaction in your example:
Code:
[blue]' Requires a reference to Microsoft XML library
Dim sURL As String
Dim strXML As String
Dim xmlhttp As MSXML2.xmlhttp

Set xmlhttp = New xmlhttp

sURL = "[URL unfurl="true"]https://xxxxxxx.xxx.com/serv/wserv.ashx"[/URL]
strXML = "u=5XXXXXX&p=XXXX&method=Method1&data=xxxxxxxxxx" 'probably - but suspect all the Xs are the result of redaction or placeholding

xmlhttp.Open "POST", sURL, False
xmlhttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
xmlhttp.send strXML
MsgBox xmlhttp.responseXML.XML 'displays any response string[/blue]
 
Thanks strongm for coming to the rescue again..


The server is off line for 12 hours from now... i will give it a test in the morning.

I used the xxx's to blank out the server address , as i felt i should keep it private...

I really need to get this going.. and will appreciate the help once again


Regards Kennedymr2
 
strongm..

I have done some testing ... the send does not come up with any error.. but i seem to get a blank response.

I have tried a few things..

Dim ll
For ll = 1 To 888888
DoEvents
Next ll

MsgBox ("a")

MsgBox (xmlhttp.responseXML.xml) 'displays any response string
MsgBox (xmlhttp.ResponseText)


Later on today i can actually check if the send is getting to the server properly.

I notice on searching the web a few other people have had this problem. but none with a "solved"

Appreciate any ideas

Regards Kennedymr2


 
Have done a little more

MsgBox (xmlhttp.ReadyState) 'result = 4 looks ok ???


MsgBox (xmlhttp.responseXML.xml) ' get nothing
MsgBox (xmlhttp.ResponseText)'get nothing
MsgBox (xmlhttp.GetAllResponseHeaders) 'get server info etc
MsgBox (xmlhttp.ResponseBody) 'nothing
MsgBox (xmlhttp.StatusText) ' get ok

Have also converted code to vb2008 and get the same as above

Maybe its a server thing...


Regards Kennedymr2

 
Have found another thing...


getallheaders... transfer-encoding chunked

is chunked the problem ????????????


regards kennedymr2
 
Server: Microsoft-IIs/6.0
X-Powerwed-By : ASP.net
X-ASpNet-Version :2.0.50727
Transfer-Encoding: chunked
Content-Type :text/html; charset = utf-8
 
>Maybe its a server thing...


I'm guessing so. If I replace sURL and strXML with known good values the code works (although on reflection I'd be using xmlhttp.ResponseText rather than the XML versiokn I originally suggested). Or perhaps the strXML is malformed - although even so I'd expect a response from the server
 
Yes i agree... i think strxml may be 'deformed'
The instruction manual is rather weak.!!!!!

I will have to speak to the server programmers..

Will let you know what the outcome is.


Thanks for your advice


Regards Kennedymr2
 
StrongM

Yes... it was one small error in the strXml.......!!!!!!!@!@

Sorry to have caused the fuss.

The string was very long and it was hard to see the potential problem..


Really appreciate the help offered.

Regards Kennedymr2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top