Microsoft MVP성태의 닷넷 이야기
Microsoft.XMLHTTP 개체로 XML 이 아닌 다른 데이터 가져오기 [링크 복사], [링크+제목 복사],
조회: 13059
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

보통 Microsoft.XMLHTTP 로 정형화된 XML 텍스트가 아니고서는 결과를 "깨진" 텍스트로 받게 됩니다.
그렇다고... 실제로 데이터가 엉뚱하게 변환되었을 리는 없을 테고.... 그냥 2진 데이터였겠죠.
 
아래의 코드에서 보면, 이진데이터를 아스키 코드로 변환해주는 VBScript 함수를 볼 수 있습니다.
 
그걸로, XMLHTTP::responseBody 속성을 해석해 주면,
정형화되지 않은 일반 텍스트 ( 한글포함 ) 문서까지도 정상적으로 반환받을 수 있습니다.
 
------ 뉴스그룹 보다가 퍼옴 ------
 


<html>
 
<head>
 
<script language=jscript>
function window.onload()
{
 var httpReq = new ActiveXObject( "Microsoft.XMLHTTP" );
 httpReq.open( "GET", "
http://webdic.ybmsisa.com/dic_search.asp", false );
 httpReq.send();
 
 alert( httpReq.responseBody );     // 여기서는 텍스트가 깨진체로 보여지지만.
 var text = BinDecode( httpReq.responseBody ); 
 alert( text );  // 여기서는 일반 ascii 텍스트로 번역되어 정상적으로 출력

}
</script>
 

<script language="vbscript">
'-----------------------------------------
' BinDecode (바이너리 -> 아스키 변환)
' mongmong - 2003. 2
'-----------------------------------------
 Public Function BinDecode(byVal binData)
  Dim i, byteChr, strV
  For i = 1 to LenB(binData)
   byteChr = AscB(MidB(binData,i,2))
   If byteChr > 127 Then
    i = i + 1
    strV = strV & Chr("&H" & Hex(byteChr) & Hex(AscB(MidB(binData,i,2))))
   Else
    strV = strV & Chr(byteChr)
   End if
  Next
  BinDecode = strV
 End Function
</script>
 

</head>
 
<body>
<FONT face="굴림"></FONT>
</body>
 
</html>







[최초 등록일: ]
[최종 수정일: 1/26/2004]


비밀번호

댓글 작성자
 




... 31  32  33  34  35  [36]  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
296정성태5/27/200612336WWF 로 만든 Tetris
294정성태5/21/200612422Session State Uses a Reader-Writer Lock
293정성태5/21/200611081Microsoft Threat Analysis & Modeling v2.0 RC1
291정성태5/18/200612370Managed Stack Explorer
289정성태5/17/200612836Microsoft ASP.NET Providers - PDF 메뉴얼
288정성태5/17/200613220TFS Administration Tool 1.0 Released...with Shared Source!
287정성태5/17/200612273An Introduction to 64-bit Installers with Visual Studio 2005: Part 1
283정성태5/15/200612838Windows Workflow Foundation: Running Service Activated Workflows on Windows Vista and IIS7
284정성태5/15/200613047    답변글 Windows Workflow Foundation: Exposing Workflows as Services [1]
281정성태5/12/200611613Microsoft Compute Cluster Pack SDK
280정성태5/11/200615818C# 3.0 : One-Step Object Creation and Initialization
279정성태5/11/200613710Vista에서 제거되는 DHTML Editing Control
278정성태5/11/200611948LINQ CTP - May 2006
286정성태5/16/200611465    답변글 Using LINQ with ASP.NET (Part 1)
277정성태5/9/200611551Web Application Projects - 정식 릴리스
276정성태5/8/200611855SNK 파일 공유하기파일 다운로드1
275정성태5/8/200611588Building Security Awareness in .NET Assemblies
274정성태5/7/200611487QuickSYS파일 다운로드2
273정성태5/7/200611775Developing Firewalls for Windows 2000/XP파일 다운로드1
272정성태5/6/200613714Windows PowerShell [3]
292정성태5/19/200611861    답변글 Windows PowerShell - PowerShell Script to Create a WorkItem
271정성태5/6/200612103MSBee
282정성태5/15/200611897    답변글 MSBee will be on CodePlex
290정성태5/18/200612361    답변글 MSBuild Extras - Toolkit for .NET 1.1 "MSBee"
270정성태5/4/200612141ISO Recorder
269정성태5/4/200612009Visual Studio 2005 Team System Level 200 Course Material
... 31  32  33  34  35  [36]  37  38  39  40  41  42  43  44  45  ...