0

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.

Ryanless
  • 134
  • 1
  • 13
  • So, this entity did not provide any other specification for accessing their Api. Some authentication method, some specific header, a token? Do they have an on-line manual, a note, that explains how a basic connection needs to be initialized? No requirements at all. Just *post a JSON formatted string and hope for the best*. – Jimi Jul 16 '18 at 10:20
  • Well, while they have send a word document with it, there is nothing of interest written. it's 95% just about which attributes are optional/required. And beside that you find only an explanation how url should look like and this: "Read Requests: GET Save Requests: POST Date-Format is always yyyy-MM-dd" – Ryanless Jul 16 '18 at 11:50
  • 1
    Well the company behind this API definitely needs to give you better support. Capture the entire request using a web debugger like [Fiddler](https://www.telerik.com/fiddler), then send it to them and have them examine/try it. Right now they're the only ones who can do anything about this. – Visual Vincent Jul 16 '18 at 12:14
  • 1
    Are POST request you do in your web browser and app identical? A 500 could indicate that there is missing data, like a single - or something (talking from experience). – CruleD Jul 16 '18 at 13:03

0 Answers0