I am making a call to an eBay api using restsharp. The code follows.
Async Sub fulfillmentPolicies()
Dim request As New RestRequest(sFulfillmentURL, Method.Get)
request.AddHeader("Authorization", "Bearer " & uT.access_token)
request.AddHeader("Content-Type", "application/json")
Try
Dim response = Await client.GetAsync(request)
If response.StatusCode = HttpStatusCode.OK Then
Dim sR As String = response.Content
Dim pP As PaymentPolicy = JsonSerializer.Deserialize(Of PaymentPolicy)(sR)
End If
Catch ex As Exception
End Try
End Sub
Client is set outside this procedure as it is used several times.
In testing when I make this call I get the error message "Cannot send a content-body with this verb-type." I can make this call successfully in Postman using the same headers. Any thoughts on what is happening here? Ways to fix?
CodePudding user response:
Content-Type
describes the format of the body in the REQUEST. It is not supposed to be used to tell the server what type of data to return.
The presence of the Content-Type header is causing an error in the .NET library as it tries to enforce the rule of not including a body with GET, and not including a header the implies a body is present.
You should be able to remove that header, but some APIs may not be compliant. It is better to sets Accepts
to indicate you accept JSON as a response.