如何从Windows 2003服务器ASP进行远程安全Web调用

时间:2014-09-10 12:42:11

标签: asp-classic

如何为Windows 2003 IIS服务器创建此类代码?

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))

2 个答案:

答案 0 :(得分:1)

我想您可以将其编译为webservice using VB.NET并从您的经典ASP网站调用using SOAP

您可能会发现,您需要扩展服务的功能,以包含其他工具,以便稍后处理您的要求。

这可能不是最佳解决方案,但需要考虑。

答案 1 :(得分:1)

我自己发现,这个VBScript代码使用user:pass凭证调用url,由于ms库中的错误,需要base64类。

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   Antonin Foller,PSTRUH软件,http://pstruh.cz Const Base64 = _   “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /”
  朦胧,我        '对于每组3个字节,对于I = 1到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