首页 > 解决方案 > 对 Google 自定义搜索 API 使用 VB GET 请求;未找到 URL 或非法请求

问题描述

我正在 VB 中创建一个程序并尝试向 Google 的自定义搜索 API 发出 GET 请求。

根据我尝试过的代码,我得到了两个回复:

在此服务器上未找到请求的 URL /customsearch/v1

或者

您的客户发出了格式错误或非法的请求

我已经尝试过使用变量,但我似乎无法弄清楚为什么会出现这些错误。这是我的代码:

Dim strHTTP As String

strHTTP = "GET /customsearch/v1"
strHTTP = strHTTP & "q=raptors"
strHTTP = strHTTP & "&key=" & mykey
strHTTP = strHTTP & "&cx=" & cxvar
strHTTP = strHTTP & " HTTP/1.1" & vbCrLf
strHTTP = strHTTP & "Host: googleapis.com" & vbCrLf
strHTTP = strHTTP & "Accept: application/json" & vbCrLf
strHTTP = strHTTP & vbCrLf

Web.SendData strHTTP

我从中得到的回应是:

在此服务器上未找到请求的 URL /customsearch/v1

当我应该得到搜索结果时。

标签: vb.net

解决方案


推荐阅读