Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > How to use HTTP protocol to get documents ?

Reply
Thread Tools

How to use HTTP protocol to get documents ?

 
 
fniles
Guest
Posts: n/a
 
      03-19-2008
I need to send a request using HTTP Protocol and it will return to me some
replies, which can be an XML or HTML file. In ASP, how can I GET/POST
documents using the HTTP protocol ?
Thank you.


 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      03-20-2008
"fniles" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I need to send a request using HTTP Protocol and it will return to me some
> replies, which can be an XML or HTML file. In ASP, how can I GET/POST
> documents using the HTTP protocol ?



Function GetText(sURL)

Dim oXHR : Set oXHR = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXHR.open "GET", sURL, False
oXHR.send
If oXHR.status = 200 Then
GetText = oXHR.responseText
Else
GetText = Null
' Or if you prefer throw an error here
End If

End Function

This simply returns a string containing the response from the server.

You could create a similar GetXML function that an XML DOM. By changing
responseText to responseXML. It will only do so if the server responds with
a content type header indicating xml.

Function PostText(sURL, vntData, sContentType)

Dim oXHR : Set oXHR = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXHR.open "POST", sURL, False
If Not IsNull(sContentType) Then oXHR.setRequestHeader "ContentType",
sContentType
oXHR.send vntData
If oXHR.status = 200 Then
PostText= oXHR.responseText
Else
PostText= Null
' Or if you prefer throw an error here
End If

End Function

Again you can mod to create a PostXML version.


--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
 
fniles
Guest
Posts: n/a
 
      03-20-2008
Thank you.
The MSXML2 only works with XML file, right ?
How about if I need to get other file other than XML file ?

Thanks

"Anthony Jones" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "fniles" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> I need to send a request using HTTP Protocol and it will return to me
>> some
>> replies, which can be an XML or HTML file. In ASP, how can I GET/POST
>> documents using the HTTP protocol ?

>
>
> Function GetText(sURL)
>
> Dim oXHR : Set oXHR = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
> oXHR.open "GET", sURL, False
> oXHR.send
> If oXHR.status = 200 Then
> GetText = oXHR.responseText
> Else
> GetText = Null
> ' Or if you prefer throw an error here
> End If
>
> End Function
>
> This simply returns a string containing the response from the server.
>
> You could create a similar GetXML function that an XML DOM. By changing
> responseText to responseXML. It will only do so if the server responds
> with
> a content type header indicating xml.
>
> Function PostText(sURL, vntData, sContentType)
>
> Dim oXHR : Set oXHR = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
> oXHR.open "POST", sURL, False
> If Not IsNull(sContentType) Then oXHR.setRequestHeader "ContentType",
> sContentType
> oXHR.send vntData
> If oXHR.status = 200 Then
> PostText= oXHR.responseText
> Else
> PostText= Null
> ' Or if you prefer throw an error here
> End If
>
> End Function
>
> Again you can mod to create a PostXML version.
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>



 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      03-20-2008
"fniles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you.
> The MSXML2 only works with XML file, right ?
> How about if I need to get other file other than XML file ?
>


No it will fetch any type of file.

Use responseText to retrieve a text based resource such as html.

Use responseBody to get an array of bytes to get a binary resource.

Use responseStream to get an implementation of IStream to pull large
resources

XMLHTTP only gets XML when 1) the response type is XML and it will build a
XML DOM which it exposes as responseXML and 2) when posting you supply an
XML DOM to the send method in which case it automatically adds the text/xml
content type and streams the xml from the DOM.



--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
HTTP GET vs HTTP POST protocol serge calderara ASP .Net Web Services 1 11-04-2005 01:27 PM
Protocol Chart - Learn how to use a Protocol Analyzer news.comcast.giganews.com Wireless Networking 0 08-21-2004 04:35 PM
use client side code to trigger the load of page must use GET Protocol? Matt ASP General 1 01-18-2004 04:09 AM



Advertisments