System.Net.HttpWebRequest equivalent

J

John

Hi

What is the System.Net.HttpWebRequest equivalent code for the MS XML related
code below?

Thanks

Regards


Set oHttpPost = CreateObject("Microsoft.XMLHTTP")
oHttpPost.Open "POST", "www.MyUrl.com", False
oHttpPost.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"

POSTData = "<data here>"

oHttpPost.Send (POSTData)

If (oHttpPost.status >= 200 And oHttpPost.status < 300) Then
St = oHttpPost.responseText
End If
 
M

Martin Honnen

John said:
What is the System.Net.HttpWebRequest equivalent code for the MS XML related
code below?
Set oHttpPost = CreateObject("Microsoft.XMLHTTP")
oHttpPost.Open "POST", "www.MyUrl.com", False
oHttpPost.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"

POSTData = "<data here>"

oHttpPost.Send (POSTData)

If (oHttpPost.status >= 200 And oHttpPost.status < 300) Then
St = oHttpPost.responseText
End If

Check out WebClient and its methods
WebClient client = new WebClient();
string st = client.UploadString("http://example.com/page.aspx",
"<data here>");
 
J

John

Hi

Many thanks. Have been reading on WebCLient but can't figure what replaces
oHttpPost.status and oHttpPost.responseText. Have googled to but couldn't
find an equivalent example.

Thanks again.

Regards
 
A

Anthony Jones

John said:
Hi

Many thanks. Have been reading on WebClient but can't figure what replaces
oHttpPost.status and oHttpPost.responseText. Have googled to but couldn't
find an equivalent example.


The responseText is the return value of a call such as UploadString().

The status isn't directly available however if a status representing a
problem in 400 or 500 range is received the call will throw a WebException.

If you need further details you can interogate the execption's properties.
For example
((HttpWebResponse)e.Response).StatusCode would get you the status code
returned by the server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top