how to fix Cannot send a content-body with this verb-type with a Post request

Mark Larsen 0 Reputation points
2024-06-16T03:44:47.1566667+00:00

I have a VB.net app that is trying to send a post request to get a token. However, I get the error above. Below is a snipit of the code in question.

    Dim client = New RestClient(stTokenURL)

    Dim request = New RestRequest(Method.Post)

    Dim result As String

    Dim stJson As String = "{"

    request.AddHeader("Accept", "application/json")

    request.AddHeader("Content-Type", "application/json")

    stJson = stJson + Chr(34) + "email" + Chr(34) + ":" + Chr(34) + stuserName + Chr(34) + ","

    stJson = stJson + Chr(34) + "password" + Chr(34) + ":" + Chr(34) + stpassword + Chr(34)

    stJson = stJson + "}"

    request.AddStringBody(stJson, DataFormat.Json)

    'request.AddParameter("application/json", stJson, ParameterType.RequestBody)

    Dim stresponse As RestResponse = client.Execute(request)

    Dim stStatusCode As String = stresponse.StatusCode.ToString
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,642 questions
{count} votes