Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

System.Net.HttpWebRequest equivalent

Question posted by: John (Guest) on March 17th, 2008 02:15 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



Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 17th, 2008
02:25 PM
#2

Re: System.Net.HttpWebRequest equivalent
John wrote:
Quote:
What is the System.Net.HttpWebRequest equivalent code for the MS XML related
code below?

Quote:
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>");

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 17th, 2008
02:35 PM
#3

Re: System.Net.HttpWebRequest equivalent
Martin Honnen wrote:
Quote:
Check out WebClient and its methods
WebClient client = new WebClient();


Add
client.Headers.Add("Content-Type",
"application/x-www-form-urlencoded");
here
Quote:
string st = client.UploadString("http://example.com/page.aspx", "<data
here>");




--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

John's Avatar
John
Guest
n/a Posts
March 17th, 2008
02:55 PM
#4

Re: System.Net.HttpWebRequest equivalent
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


"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:OMX7YkDiIHA.4744@TK2MSFTNGP06.phx.gbl...
Quote:
John wrote:
>
Quote:
>What is the System.Net.HttpWebRequest equivalent code for the MS XML
>related
>code below?

>
Quote:
>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>");
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/




Anthony Jones's Avatar
Anthony Jones
Guest
n/a Posts
March 19th, 2008
10:05 PM
#5

Re: System.Net.HttpWebRequest equivalent
"John" <info@nospam.infovis.co.ukwrote in message
news:eyJIP0DiIHA.4536@TK2MSFTNGP06.phx.gbl...
Quote:
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.



--
Anthony Jones - MVP ASP/ASP.NET



 
Not the answer you were looking for? Post your question . . .
189,798 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors