Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 我的http GET有什么问题?_String_Http_Vba_Url_Get - Fatal编程技术网

String 我的http GET有什么问题?

String 我的http GET有什么问题?,string,http,vba,url,get,String,Http,Vba,Url,Get,在VBA中,我正在创建一个URL: URL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=" & yahoo & "&street=" & street & "&city=" & city & "&state=" & state & "&zip=" & zip 例如,它将自身设置为等于: http://api.local

在VBA中,我正在创建一个URL:

URL = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=" & yahoo & "&street=" & street & "&city=" & city & "&state=" & state & "&zip=" & zip
例如,它将自身设置为等于:

http://api.local.yahoo.com/MapsService/V1/geocode?appid=username123&street=1893 n. clyde morris blvd &city=daytona beach&state=FL&zip=32117
当我手动转到此URL时,它工作正常

但是,当我这样做时:

'Create Http object
If IsEmpty(http) Then Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

'Send request To URL
http.Open "GET", URL

http.send
'Get response data As a string

response = http.responseText
它给了我这个回应:

response="Watch :   : response : "<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Yahoo! - 400 Bad Request</title><style>
/* nn4 hide */ 
/*/*/
bod........"
response=“监视::响应:”
雅虎400错误请求
/*nn4隐藏*/
/*/*/
董事会……。”
请注意,50%的时间它返回正确的URL,50%的时间它给我一个
400错误请求

我做错了什么


wrikken建议我使用URLencoder,但我相信它的编码是正确的!

您需要对所有查询参数进行url编码,否则它们可能会导致无效url,具体取决于它们的实际值(例如,空格应该是
+
%20
)。谷歌有很多VBA url编码示例,似乎没有内置的功能。

@wrikken:非常感谢您的帮助。您能给我举个例子吗?'wrikken':“谷歌有很多VBA url编码示例。”@wrikken:谢谢。我得到的url没有使用公认的协议”-这意味着什么?@Jenny:那么您可能正在对整个url进行编码(伪代码:
url编码(url)
),这不是您想要的,您只想对值进行编码(伪代码:
)http://api.local.yahoo.com/MapsService/V1/geocode?appid=“&url编码(yahoo)和”&street=“&url编码(street)&…等等
@wrikken:再次感谢你。现在我得到了像这样疯狂的东西“