Internal : Could not execute code stage because exception thrown by code stage: Object reference not set to an instance of an object.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
17-11-22 12:30 AM
Hi , Facing the Internal : Could not execute code stage because exception thrown by code stage: Object reference not set to an instance of an object issue when I try to use the HTTP post request. I tested it via postman and able to get the response but the same inputs are not working in BP.
Could someone please help me on this. Attaching the screenshots for the same.
Here is the code.
Try
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
' Normal stream writer, we aren't encoding a file etc.
If Not usingFile Then
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
Else If usingFile Then
' Prep the request body
Dim byteArray = File.ReadAllBytes( body )
Dim requestStream As IO.Stream = request.GetRequestStream()
requestStream.Write(byteArray,0, byteArray.Length)
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
Catch e As WebException
Using response As WebResponse = e.Response
Dim httpResponse As HttpWebResponse = CType(response, HttpWebResponse)
Using data As Stream = response.GetResponseStream()
Using reader = New StreamReader(data)
Dim text As String = reader.ReadToEnd()
resultData = resultData + text
End Using
End Using
End Using
End Try
------------------------------
vikas kalwala
------------------------------
Could someone please help me on this. Attaching the screenshots for the same.
Here is the code.
Try
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
' Normal stream writer, we aren't encoding a file etc.
If Not usingFile Then
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
Else If usingFile Then
' Prep the request body
Dim byteArray = File.ReadAllBytes( body )
Dim requestStream As IO.Stream = request.GetRequestStream()
requestStream.Write(byteArray,0, byteArray.Length)
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
Catch e As WebException
Using response As WebResponse = e.Response
Dim httpResponse As HttpWebResponse = CType(response, HttpWebResponse)
Using data As Stream = response.GetResponseStream()
Using reader = New StreamReader(data)
Dim text As String = reader.ReadToEnd()
resultData = resultData + text
End Using
End Using
End Using
End Try
------------------------------
vikas kalwala
------------------------------
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
17-11-22 02:39 AM
@vikas kalwala,
So you're using the Utility - HTTP VBO, correct? If so, are you using the latest version from the DX (see the link below)? Can you paste a screenshot of the properties you've set for the action?
https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---http
Cheers,
------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------
So you're using the Utility - HTTP VBO, correct? If so, are you using the latest version from the DX (see the link below)? Can you paste a screenshot of the properties you've set for the action?
https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---http
Cheers,
------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
17-11-22 03:25 AM
When I use the HTTP VBO from the link you mentioned its throwing the error-
Exception: The underlying connection was closed: An unexpected error occurred on a send.
Inner Exception: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I use HTTP request action with Header, Body(with JSON text) and address URL.
Force pre auth- False,
Use proxy - False & Content-Type- application/json
In the Headers collection I pass only the API key.
With the one header(api key) it is working in postman but not in BP.
Sorry I am unable to upload the screenshot as Iam in restricted network.
------------------------------
vikas kalwala
------------------------------
Exception: The underlying connection was closed: An unexpected error occurred on a send.
Inner Exception: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I use HTTP request action with Header, Body(with JSON text) and address URL.
Force pre auth- False,
Use proxy - False & Content-Type- application/json
In the Headers collection I pass only the API key.
With the one header(api key) it is working in postman but not in BP.
Sorry I am unable to upload the screenshot as Iam in restricted network.
------------------------------
vikas kalwala
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
17-11-22 01:15 PM
@vikas kalwala,
So you're using an API key. Does that need to be placed in the Authorization header, and is it considered a Bearer token? If so, you do not want to add it via the Headers collection. Instead, you want to set the User Bearer Token property to True and then place your API key in the Bearer Token property.

Cheers,
------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------
So you're using an API key. Does that need to be placed in the Authorization header, and is it considered a Bearer token? If so, you do not want to add it via the Headers collection. Instead, you want to set the User Bearer Token property to True and then place your API key in the Bearer Token property.
Cheers,
------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------
