MSXML2.ServerXMLHTTP 이용해서 웹페이지 읽기
Posted at 2010. 2. 3. 00:07 | Posted in 프로그래밍/ASP, Javascript가장 기본적인 방법은 다음과 같다.
<%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
%>
'프로그래밍 > ASP, Javascript' 카테고리의 다른 글
ASP 글자수 제한하기 (0) | 2010.10.22 |
---|---|
자바스크립트 숫자만 입력 받기(한글 입력 불가) (0) | 2010.10.22 |
체크박스 한개일때와 여러개일때 구분해서 오류없게 처리하기 (0) | 2009.07.02 |
HTML 문자 표 (0) | 2009.01.24 |
이미지 페이드인 (0) | 2008.12.22 |