引子: VB6是一種比較早的高級語言,但可以說在它那個時代非常流行,本人就遇到不少項目用該語言進行開發,但隨著Java, .net等其它新語言的發展,VB6已經漸漸淡出了,但不少其開發的項目卻被保留了下來。目前遇到的一個困擾就是這樣的系統如何解決與新語言開發的系統的數據交互問題。本文就先拋一個話題,VB6實現基于HTTP Web調用來解決與基于B/S架構的應用程序間的調用(示例使用Java開發)。
一、整體方案介紹
說明: VB客戶端使用msxml.dll組件,創建XMLHTTP對象,通過該對象以HTTP方式訪問WebServer請求,提交數據并取得返回的數據結果
二、如何使用MSXML組件進行開發
a)
MSXML組件引入項目
MSXML組件引入項目比較簡單,方法如下圖所示:

注:建議使用MSXML v6.0版本,如果本地沒有可上官網上下載。
客戶端代碼編寫
1 Dim xmlhttp As XMLHTTP60
2 Set xmlhttp = New XMLHTTP60
3
4 Dim url As String
5 url = “http://localhost:8080/simplewebapps/jsp/test.jsp”
6 Dim postData As String
7 postData = “<data><value>post data提交數據</value></data>”
8
9 xmlhttp.open "POST", url, False
10 xmlhttp.setRequestHeader "User-Agent", "MyCustomUser"
11
12 If IsNull(postData) Then
13 xmlhttp.send
14 Else
15 xmlhttp.send postData
16 End If
17
18 Dim responseText AS String
19 ‘解析返回的xml數據格式
20 responseText = xmlhttp.responseText
21
22 Set xmlhttp = Nothing
23
服務器代碼編寫(Jsp示例)
1 <%
2 //取得提交的參數
3 String postData = “”;
4 String str;
5 While ( (str = request.getReader().readLine()) != null) {
6 postData += str;
7 }
8
9 //deal post data and response back data as XML format
10 out.println(“<root> <Node1>”+postData +” </Node1> </root>”);
11 %>
12
參考資料
MSDN
MSXML SDK http://msdn.microsoft.com/en-us/library/ms759148(VS.85).aspx
MSXML6.0 下載鏈接
http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
本文只是拋磚引玉,如果大家更好意見和建議,歡迎大家提出來分享。
本文示例下載
Good Luck!
Yours Matthew!
posted on 2008-08-19 08:50
x.matthew 閱讀(5627)
評論(1) 編輯 收藏 所屬分類:
其它