1
我想在我的grails項目中使用垂直響應api。但它給下面的錯誤grails中的垂直響應api
CODE:
def http = new HTTPBuilder()
http.request('https://vrapi.verticalresponse.com/',GET, TEXT) { req ->
uri.path = 'api/v1/contacts?type=basic'
headers.'Authorization' = 'Bearer api_token'
headers.'Content-Type'='application/json'
print('====================================')
response.success = { resp, reader ->
assert resp.status == 200
println "My response handler got response: ${resp.statusLine}"
println "Response length: ${resp.headers.'Content-Length'}"
reader // print response reader
}
// called only for a 404 (not found) status code:
response.'404' = { resp ->
println 'Not found'
}
}
錯誤:
Unauthorized. Stacktrace follows:
groovyx.net.http.HttpResponseException: Unauthorized
at groovyx.net.http.HTTPBuilder.defaultFailureHandler(HTTPBuilder.java:652)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:441)
at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:417)
...
你真的發送'api_token',是否正確? – Opal
可能是你在標頭中發送錯誤的api標誌(或X-Auth-Token)。'授權'。你有沒有嘗試過使用[Rest Client Builder Plugin](https://grails.org/plugin/rest-client-builder)。它使調用REST調用非常簡單。 –
傳遞令牌是有效的,我已經測試了它使用郵遞員擴展的鉻和它的工作沒有任何問題 –