1
Guys, I’m having trouble with the mistake "Cannot send a content-body with this Verb-type.". I’ve changed the method to POST
, but the API only accepts if the given method is GET
.
I’ve tried to send the body
as header
, and the API also does not accept.
When searching vi that for Webrequest it is not possible to send a body
via the method GET
.
Can you help me? Below is the code I’m using in Visual Basic.
Dim request As HttpWebRequest = HttpWebRequest.Create(URL)
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
request.Headers.Add("Authorization", "Bearer " + base64)
request.Method = "GET"
request.ContentType = "application/json"
Dim httpRequest As HttpWebRequest = TryCast(request, HttpWebRequest)
If Not String.IsNullOrEmpty(body) Then
Dim requestStream As IO.Stream = request.GetRequestStream()
Using sw As New IO.StreamWriter(requestStream, New Text.UTF8Encoding(False))
sw.Write(body)
End Using
End If
Using response As WebResponse = request.GetResponse()
Dim responseStream As IO.Stream = response.GetResponseStream()
Dim sr As New IO.StreamReader(responseStream)
resultData = sr.ReadToEnd()
End Using
Do you have control over this API in order to change it? Does this method of it NEED to be GET? Can this body be passed via parameter? Say what the initial problem is: the problem that when trying to solve led you to this question problem, because it looks like XY problem
– Ronaldo Araújo Alves
@Ronaldoaraújoalves, I have no control over this API to be able to change it. The method needs to be GET. Body can be passed as parameter. I searched how to send via parameter using the Httpwebrequest class but found nothing.
– William de Almeida Silva
@Ronaldoaraújoalves This API is from a supplier of the company I work for, and I need to send a body with some filters so that I receive a list of protocols. The real problem is that I went to use the code above, and I get the error message: Cannot send a content-body with this Verb-type.
– William de Almeida Silva