我正在请求来自此 API 的结果: http://mlrs.research.um.edu.mt/resources/gabra-api/
一切正常,除非我引入马耳他字符(UTF-8)。
如果我手动使用以下网址请求数据,返回是正确的。 http://mlrs.research.um.edu.mt/resources/gabra-api/lexemes/search?s=għar
...search?s=ċar(目前不能发布超过两个链接。)
使用以下代码时,返回为空。
{"results":[],"query":{"page":1,"page_size":20,"result_count":0,"term":"g?ar","search_lemma":true,"search_wordforms":true,"search_gloss":true,"pending":false,"pos":null,"source":null}}
{"results":[],"query":{"page":1,"page_size":20,"result_count":0,"term":"?ar","search_lemma":true,"search_wordforms":true,"search_gloss":true,"pending":false,"pos":null,"source":null}}
注意?替换 ħ 和 ċ 字符 - 那只是因为我从即时窗口复制了这些字符。
这是我用来发出请求的代码:
Public Function GetWebSource(ByRef Url As String) As String
Dim xml As IXMLHTTPRequest
On Error Resume Next
Set xml = CreateObject("Microsoft.XMLHTTP")
With xml
.Open "GET", Url, False
.send
GetWebSource = .responseText
End With
Set xml = Nothing
End Function
因为 VBA IDE 不支持这些字符,所以需要从表单域进行测试。
任何帮助,非常感谢。
提前致谢。
斯蒂芬
最佳答案
该 URL 包含一些非 ASCII 字符,因此您必须事先对它们进行编码:
Set xhr = CreateObject("Microsoft.XMLHTTP")
xhr.Open "GET", "http://mlrs.research.um.edu.mt/resources/gabra-api/lexemes/search?s=g%C4%A7ar", False
xhr.Send
关于html - 从 VBA 代码中请求带有 UTF-8 字符的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46016716/