0
我想要得到的响应的HttpWebRequest的使用GET方法和内容类型的JSON .. 但我越来越Cannot send a content-body with this verb-type
获取使用JSON使用GET HTTP web请求
这里是我的代码:
Dim objRequest As HttpWebRequest = WebRequest.Create(url)
Dim reqBytes As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(strPost)
objRequest.Method = "GET"
objRequest.Timeout = "15000"
objRequest.ContentLength = reqBytes.Length
objRequest.ContentType = "application/json; charset=utf-8"
Try
myWriter = objRequest.GetRequestStream()
myWriter.Write(reqBytes, 0, reqBytes.Length)
Catch e As Exception
writetotext(e.toString)
End Try
我错过了什么吗?
好吧,所以我删除了这个'objRequest.ContentType =“application/json; charset = utf-8”'但我需要得到请求的响应,因为json有什么我必须添加的? – User7291
尝试'objRequest.Accept =“application \ json”'。但主要问题是您无法写入请求流。 GET不能有消息体。您使用'strPost'形式的有效载荷既可以使用“POST”方法发送,也可以以查询字符串的形式传入。 – Badri