I am sending a request to external API from my application using HttpWebRequest and HttpWebResponse.
Whenever there is an error in XML request due to some wrong values passed in XML nodes, then there is a 400 Bad request error response and the error message is "There is an error in XML document (51, 14)". The problem is if there is an error in request XML, the response XML should display the error message with correct line number. but I am receiving an error message with incorrect line number and it is always "There is an error in XML document (1, 1254)". There is actually no error at line 1. Due to this issue, I have no chance to point to the error when troubleshooting.
Can you help how do I get Response with the correct line number in XML.
Thanks
What I have tried:
Below is my existing code in vb to send the request to API.
Dim Wreq As HttpWebRequest
Dim MyURI As String = String.Empty
Dim bytes() As Byte
Try
MyURI = p_strURL
Wreq = HttpWebRequest.Create(MyURI)
Wreq.Method = "POST"
bytes = System.Text.Encoding.UTF8.GetBytes(pi_strRequestXML)
Wreq.ContentLength = bytes.Length 'pi_strRequestXML.Length
Wreq.ContentType = "application/x-www-form-urlencoded"
Wreq.KeepAlive = False
Wreq.Headers.Add("Authorization", "bearer" + " " + strAccessToken)
Using OutputStream As StreamWriter = New StreamWriter(Wreq.GetRequestStream())
OutputStream.Write(pi_strRequestXML)
End Using
Using Wres As HttpWebResponse = Wreq.GetResponse()
Using loResponseStream As StreamReader = New StreamReader(Wres.GetResponseStream())
oResponse = loResponseStream.ReadToEnd()
End Using
End Using
Return oResponse
Catch e As WebException
Throw
Catch objSysEx As Exception
Throw
Finally
End Try