Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2008

Tip: Looking for answers? Try searching our database.

System.Net.HttpWebRequest equivalent

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 17 Mar 2008 15:03 GMT
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 - 17 Mar 2008 15:13 GMT
> 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
[quoted text clipped - 8 lines]
>   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>");

Signature

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

Martin Honnen - 17 Mar 2008 15:25 GMT
> Check out WebClient and its methods
>   WebClient client = new WebClient();

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

Signature

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

John - 17 Mar 2008 15:41 GMT
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

>> What is the System.Net.HttpWebRequest equivalent code for the MS XML
>> related
[quoted text clipped - 17 lines]
>   string st = client.UploadString("http://example.com/page.aspx", "<data
> here>");
Anthony Jones - 19 Mar 2008 23:01 GMT
> 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.

Signature

Anthony Jones - MVP ASP/ASP.NET


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.