来自RallyDev API的“GET”响应中的垃圾

时间:2015-02-25 21:21:22

标签: vba excel-vba rally excel

我在Excel中有一个功能:

Function getState(Defects As Object) As String

Dim str As String
Dim res As String
Dim was As Boolean
Dim sURL As String
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")

was = False

For Each defect In Defects
    If was = False Then
        str = "(FormattedID = """ & defect & """)"
        res = str
        was = True
    Else
        res = res & " OR " & str
    End If
Next defect

sURL = "https://rally1.rallydev.com/slm/webservice/v2.0/defect?query=(" & res & ")&fetch=FormattedID,State"

oRequest.Open "GET", sURL, True
oRequest.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
oRequest.Send
oRequest.WaitForResponse
' Set Defects = oRequest.ResponseText
Debug.Print (oRequest.ResponseText)

End Function

不幸的是,我得到垃圾而不是json作为回应: ?我?ANA0E?= A(UTU ¤RoP°IRC°%的” o $%·CI {OOYO ???? uApeaBRM ZBùOWO “{oSCy5(}ê??éQBA?” qnu〜·E·的Uu |。??????ARBE? a>aμ?c?9P =?A [Oul?0i O {PZS?Af~ ???????????????????????? ?#?AjAa?\aC¤y%©e»]“IHog ?? @:?·(??”¶E9yog?Az?7bw?/#?eWp ^ u?ZU?u ?? 3?q?A )cy7μe?E

您能否看一下它并提供解决方法如何解决?

提前谢谢!

2 个答案:

答案 0 :(得分:1)

响应被压缩。尝试为Accept-Encoding设置请求标头:identity或解压缩响应。

答案 1 :(得分:1)

拉里的回答是正确的。

顺便说一句,如果您需要将数据从Rally提取到Excel中,最好的选择是Excel的Rally插件:

https://help.rallydev.com/rally-add-excel

由于您提到了VBA,您可能正在使用Excel加载项不支持的Excel中构建一些自动化。有一个用于VBA的alpha级Rally Rest Toolkit。它为您处理身份验证和REST序列化/反序列化,因此它可以减轻您的一些编码工作。

这是非官方的,不受拉力赛的支持,但值得尝试。由于它不受支持,如果遇到问题,Rally无法帮助您。您必须针对VBA工具包重构自己的代码以提取所需的数据:

https://github.com/markwilliams970/RallyRestToolkitForVBA