2017-09-02 46 views
2

我请求从这个API结果UTF-8字符: http://mlrs.research.um.edu.mt/resources/gabra-api/请求URL与VBA代码

一切正常,除非我介绍的马耳他字符(这是UTF-8)的罚款。

如果我使用以下URL手动请求数据,则返回是正确的。 http://mlrs.research.um.edu.mt/resources/gabra-api/lexemes/search?s=għar

...搜索?S = CAR(不能发布两个以上的链路还没有。)

使用下面的代码,返回的是空白。

{"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不支持这些字符,测试将需要从表单字段来完成。

任何帮助,非常感谢。

在此先感谢。

斯蒂芬

回答

1

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