So my goal is to send a HttpRequest to api, it returns a 500 internal server error. According to them, other companies are succesfully using this Api, so it should work in theory. I send the json example string I use to test if it works, they confirmed it is correct. So what could cause the Error?
Public Function SendStringToHttpServer(dataString As String, uriString As String, credentials As NetworkCredential) As String
Dim resultInfo As String
Dim request As HttpWebRequest = CType(WebRequest.Create(uriString), HttpWebRequest)
request.Credentials = credentials
request.Timeout = 6000
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(dataString)
request.ContentType = "application/json"
request.ContentLength = byteArray.Length
Try
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
response.Close()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Return "done"
End Function
Note: I saw there are some similiar threads, like this. But I use it exactly the same way, so it SHOULD work but doesn't -.- (Beside the fact that i have strict on and therefore cast explicitly)
EDIT: About the authentification methods: This works definitly, since if I use wrong username or password in the credenitals I get a 403: authorized Error and not a 500.
Furthermore the read request works just fine. Read request is very similiar just a basic HttpRequest which only requires the url and credentials.
EDIT 2: So I read that it can be tied to HttpRequest automaticlly adding and "Expect:100-continue" to the header.I prevent this now
ServicePointManager.Expect100Continue = False
But it still gives a 500 Error.