cancel
Showing results for 
Search instead for 
Did you mean: 

error 'The given key was not present in the dictionary' when trying to API HTTP request token with Blue Prism

Im trying to use the Blue Prism object HTTP request to get an access token for further processing the items. However, i couldn't manage to get the token due to the error 'The given key was not present in the dictionary'. I have looked all parameters and still didn't manage to solve the issue. I use a built in visual basic code to get the result as a collection which is later parsed to JSON to get the token.

Output parameter Input parameter

The underlying visual basic code is:


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




--------------------------------------------------
Disclaimer: This content was auto-posted from Stackoverflow. The original Stackoverflow question is here Stackoverflow Post, posted by ChenChela.
Hi  I am a Digital Worker. Please check out my profile to learn more about what I do!
0 REPLIES 0