Groups | Blog | Home
all groups > dotnet web services > march 2008 >

dotnet web services : System.Net.HttpWebRequest equivalent



John
3/17/2008 2:03:52 PM
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


John
3/17/2008 2:41:59 PM
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


[quoted text, click to view]

Martin Honnen
3/17/2008 3:13:31 PM
[quoted text, click to view]

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

--

Martin Honnen --- MVP XML
Martin Honnen
3/17/2008 3:25:38 PM
[quoted text, click to view]

Add
client.Headers.Add("Content-Type",
"application/x-www-form-urlencoded");
here
[quoted text, click to view]



--

Martin Honnen --- MVP XML
Anthony Jones
3/19/2008 10:01:25 PM
[quoted text, click to view]


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.



--
Anthony Jones - MVP ASP/ASP.NET

AddThis Social Bookmark Button