尝试使用 Blue Prism API HTTP 请求令牌时出现错误 'The given key was not present in the dictionary'
error 'The given key was not present in the dictionary' when trying to API HTTP request token with Blue Prism
我正在尝试使用 Blue Prism 对象 HTTP 请求来获取访问令牌以进一步处理项目。但是,由于错误 'The given key was not present in the dictionary',我无法获取令牌。我查看了所有参数,但仍然无法解决问题。我使用内置的 Visual Basic 代码将结果作为集合获取,稍后将其解析为 JSON 以获取令牌。
底层的 visual basic 代码是:
Dim request As WebRequest = WebRequest.Create(addressURL)
If forcePreAuth Then
'Sometimes a web server will require the authorisation header in the initial request
'In which case we have to add the basic authorization header manually.
Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(String.Format("{0}:{1}",username,password))
Dim base64 As String = Convert.ToBase64String(bytes)
request.Headers.Add("Authorization", "Basic " & base64)
Else
If Not String.IsNullOrEmpty(username) AndAlso Not String.IsNullOrEmpty(password) Then
request.Credentials = New NetworkCredential(username,password)
End If
End If
If useProxy Then
Dim proxyURI As New Uri(proxyURL)
Dim proxy As New WebProxy(proxyURI, True)
Dim proxyCred As New NetworkCredential(proxyUsername, proxyPassword)
Dim credCache As New CredentialCache()
credCache.Add(proxyURI, "Basic", proxyCred)
proxy.UseDefaultCredentials = False
proxy.Credentials = credCache
request.Proxy = proxy
End If
request.Method = method
request.ContentType = contentType
Dim httpRequest As HttpWebRequest = TryCast(request, HttpWebRequest)
If httpRequest IsNot Nothing Then
If Not String.IsNullOrEmpty(accept) Then
httpRequest.Accept = accept
End If
If Not String.IsNullOrEmpty(certID) Then
httpRequest.ClientCertificates.Add(m_Certificates(certID))
End If
End If
For Each r As DataRow In headers.Rows
For Each c As DataColumn In headers.Columns
Dim columnName As String = c.ColumnName
Dim val As String = r(columnName).ToString
request.Headers.Add(columnName,val)
Next
Exit For 'Only one row is allowed
Next
If Not String.IsNullOrEmpty(body) Then
Dim requestStream As IO.Stream = request.GetRequestStream()
Using sw As New IO.StreamWriter(requestStream, New Text.UTF8Encoding(False))
sw.Write(body)
End Using
End If
Using response As WebResponse = request.GetResponse()
Dim responseStream As IO.Stream = response.GetResponseStream()
Dim sr As New IO.StreamReader(responseStream)
resultData = sr.ReadToEnd()
End Using
截图:
输入参数
输入参数请求令牌
请求令牌:
输出参数:
Blue Prism 在证书方面使用了一些特殊的模式。 Utility - HTTP
对象的设计方式是允许将证书文件(.cer
等)即时加载到本地证书存储中,每个证书分配一个新的 Certificate ID
时间。
在触发您的 HTTP Request
之前,使用同一个 Utility - HTTP
对象中的 Load Certificate
操作输出有效的 Certificate ID
,然后您可以将其传递给 [=13] =]的Certificate ID
参数。
我正在尝试使用 Blue Prism 对象 HTTP 请求来获取访问令牌以进一步处理项目。但是,由于错误 'The given key was not present in the dictionary',我无法获取令牌。我查看了所有参数,但仍然无法解决问题。我使用内置的 Visual Basic 代码将结果作为集合获取,稍后将其解析为 JSON 以获取令牌。
底层的 visual basic 代码是:
Dim request As WebRequest = WebRequest.Create(addressURL)
If forcePreAuth Then
'Sometimes a web server will require the authorisation header in the initial request
'In which case we have to add the basic authorization header manually.
Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(String.Format("{0}:{1}",username,password))
Dim base64 As String = Convert.ToBase64String(bytes)
request.Headers.Add("Authorization", "Basic " & base64)
Else
If Not String.IsNullOrEmpty(username) AndAlso Not String.IsNullOrEmpty(password) Then
request.Credentials = New NetworkCredential(username,password)
End If
End If
If useProxy Then
Dim proxyURI As New Uri(proxyURL)
Dim proxy As New WebProxy(proxyURI, True)
Dim proxyCred As New NetworkCredential(proxyUsername, proxyPassword)
Dim credCache As New CredentialCache()
credCache.Add(proxyURI, "Basic", proxyCred)
proxy.UseDefaultCredentials = False
proxy.Credentials = credCache
request.Proxy = proxy
End If
request.Method = method
request.ContentType = contentType
Dim httpRequest As HttpWebRequest = TryCast(request, HttpWebRequest)
If httpRequest IsNot Nothing Then
If Not String.IsNullOrEmpty(accept) Then
httpRequest.Accept = accept
End If
If Not String.IsNullOrEmpty(certID) Then
httpRequest.ClientCertificates.Add(m_Certificates(certID))
End If
End If
For Each r As DataRow In headers.Rows
For Each c As DataColumn In headers.Columns
Dim columnName As String = c.ColumnName
Dim val As String = r(columnName).ToString
request.Headers.Add(columnName,val)
Next
Exit For 'Only one row is allowed
Next
If Not String.IsNullOrEmpty(body) Then
Dim requestStream As IO.Stream = request.GetRequestStream()
Using sw As New IO.StreamWriter(requestStream, New Text.UTF8Encoding(False))
sw.Write(body)
End Using
End If
Using response As WebResponse = request.GetResponse()
Dim responseStream As IO.Stream = response.GetResponseStream()
Dim sr As New IO.StreamReader(responseStream)
resultData = sr.ReadToEnd()
End Using
截图:
输入参数
输入参数请求令牌
请求令牌:
输出参数:
Blue Prism 在证书方面使用了一些特殊的模式。 Utility - HTTP
对象的设计方式是允许将证书文件(.cer
等)即时加载到本地证书存储中,每个证书分配一个新的 Certificate ID
时间。
在触发您的 HTTP Request
之前,使用同一个 Utility - HTTP
对象中的 Load Certificate
操作输出有效的 Certificate ID
,然后您可以将其传递给 [=13] =]的Certificate ID
参数。