HTTP를 구현해 놓은 여러 컴포넌트들이 있지만 윈도우2000에서부터 기본으로 설치되는 MSXML2.ServerXMLHTTP 컴포넌트를 이용하여 원격 웹서버의 내용을 갖고 올수 있다.
가장 기본적인 방법은 다음과 같다.
- <%
- sUrl = "http://www.ecplaza.net/"
- set oHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
- oHttp.Open "GET", sUrl, False
- oHttp.Send ""
- Response.Write oHttp.ResponseText
- Set oHttp = Nothing
- %>
GET 메쏘드로 갖고온 HTML을 화면에 출력하는 루틴이다. 게시판등에 글을 쓰거나 할 때는 POST 메쏘드를 사용하는데 이 방법도 가능한다.
- <%
- sUrl = "http://river.ecplaza.net/form.asp"
- set oHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
- oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- oHttp.Open "POST", sUrl, False
- oHttp.Send "subject=test&contents=message+body"
- Response.Write oHttp.ResponseText
- Set oHttp = Nothing
- %>
오류 처리는 Send 메쏘드를 호출하기 전에 On Error Resume Next를 적어주고 오류발생여부를 체크하면 된다.
- <%
- sUrl = "http://river.ecplaza.net/form.asp"
- set oHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
- oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
-
- On Error Resume Next
-
- oHttp.Send "subject=test&contents=message+body"
- If Err Then
- Response.Write "Error:" & oHttp.ParseError.URL & "<br>" & _
- oHttp.ParseError.Reason
- Else
- Response.Write oHttp.ResponseText
- End If
- Set oHttp = Nothing
- %>
출처 http://pluto.ecplaza.net:8080/tt/river/226