473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

System.Net.HttpWebRequest equivalent

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

Mar 17 '08 #1
4 4311
John wrote:
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>");

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 17 '08 #2
Martin Honnen wrote:
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>");


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 17 '08 #3
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" <ma*******@yahoo.dewrote in message
news:OM**************@TK2MSFTNGP06.phx.gbl...
John wrote:
>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>");

--

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

Mar 17 '08 #4
"John" <in**@nospam.infovis.co.ukwrote in message
news:ey**************@TK2MSFTNGP06.phx.gbl...
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
Mar 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martyn Wynne | last post by:
Hi, Can anyone please tell me if there is any reason why when i am streaming from a webrequest (decompressing on route) to a file on the hard drive, i would be getting an exception of Filestream...
0
by: Mackuack | last post by:
Hello everybody i have the following code to access an application via https: --------------------------------------------- System.Net.ServicePointManager.CertificatePolicy = new...
0
by: yariv | last post by:
Hello All, I am having a very strange problem. while trying to access http page on the web using HTTPWebRequest Class, I happen to have some problems at specific machines. The exception I...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
1
by: jmhmaine | last post by:
I've used the WebClient class on a few projects but I wanted to know if anyone could point to the good resource for Best Practices with this object. The two things I haven't seen in sample code...
1
by: etantonio | last post by:
Good morning, I've a problem, in the past I translate my site from google or altavista with a code similar to this : <%@ Page Language="c#" Trace="true" Debug="true" %> <%@ import...
1
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've...
1
by: ibaldwinjr | last post by:
Hi, I am trying to get a response from a URL using the HttpWebRequest object. this is my code below. httpRequest = (HttpWebRequest) WebRequest.Create(myurl); httpRequest.Method = "GET";...
4
by: John | last post by:
Hi What is the System.Net.HttpWebRequest equivalent code for the MS XML related code below? Thanks Regards
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.