가장 기본적인 방법은 다음과 같다.
< %
sUrl = "http://www.youngsam.kr/"
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://youngsam.kr/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://youngsam.kr/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
%>
2012/02/07 09:59 2012/02/07 09:59

Trackback Address :: https://youngsam.net/trackback/1754