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