2014-09-10 59 views
-1

如何爲Windows 2003 IIS服務器創建此類代碼?如何從Windows 2003服務器進行遠程安全的Web呼叫ASP

Dim req as New WebClient() 

Dim myCache As New CredentialCache() 
myCache.Add(New Uri(URL), "Basic", _ 
      New NetworkCredential(Username, Password)) 

req.Credentials = myCache 

Dim results as String 
results = System.Encoding.UTF8.GetString(req.DownloadData(URL)) 
+1

這是因爲你在那裏的代碼看起來更像VB.NET,而不是VBScript。 – Paul 2014-09-10 12:48:57

+0

VBScript是否有類似的解決方案? – Tom 2014-09-11 07:49:38

回答

1

發現它我自己,這個VBScript代碼調用URL與用戶:傳遞憑據,base64類是必需的,由於ms庫中的錯誤。

Dim http: Set http = Server.CreateObject("MSXML2.ServerXMLHTTP") 
dim url 
url = "any.html" 
http.open "GET", url, False,"user","pass" 
http.setRequestHeader "Authorization", "Basic " & Base64Encode("user:pass") 
http.send 

功能Base64Encode(INDATA) '撕開從: ' http://www.pstruh.cz/tips/detpg_Base64Encode.htm「RFC1521 '2001 安東尼Foller,PSTRUH軟件,http://pstruh.cz CONST的Base64 = _ 「ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/」
昏暗SOUT,我 '對於每個3字節的組For I = 1 To Len(inData)步驟3 Dim nGroup,pOut

'Create one long from this 3 bytes. 
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _ 
    &H100 * MyASC(Mid(inData, I + 1, 1)) + _ 
    MyASC(Mid(inData, I + 2, 1)) 

'Oct splits the long To 8 groups with 3 bits 
nGroup = Oct(nGroup) 

'Add leading zeros 
nGroup = String(8 - Len(nGroup), "0") & nGroup 

'Convert To base64 
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _ 
    Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _ 
    Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _ 
    Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1) 

'Add the part To OutPut string 
sOut = sOut + pOut 
    Next Select Case Len(inData) Mod 3 
Case 1: '8 bit final 
    sOut = Left(sOut, Len(sOut) - 2) + "==" 
Case 2: '16 bit final 
    sOut = Left(sOut, Len(sOut) - 1) + "=" 
    End Select Base64Encode = sOut End Function 
+0

不是最好的答案,也沒有解釋你已經包含了對'Base64Encode()'函數的引用,但不提供其他用戶的來源。考慮改善答案不僅僅是爲了你自己,而是爲了其他人。 – Lankymart 2014-09-12 17:42:29

1

我想你可以編譯這個到webservice using VB.NET,讓您傳統的ASP網站,它using SOAP電話。

您可能會發現需要擴展該服務的功能以包含其他設施以便稍後處理您的需求。

這可能不是最好的解決方案,但這是需要考慮的問題。