0
製造商:0.7.1 | 語言:Groovy | 框架:斯波克HTTPBuilder爲什麼會拋出「HttpResponseException:Bad Request」?
測試代碼
import groovyx.net.http.HTTPBuilder
import spock.lang.Specification
/**
* Created by Long Nguyen on 4/11/2017.
*
* Chatwork api documentation: http://developer.chatwork.com/ja/index.html
*/
class ChatworkApiSpec extends Specification {
// https://api.chatwork.com/v2/contacts
def apiRoot = "http://api.chatwork.com/v2"
def contactsPath = "/contacts"
def apiToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
def http = new HTTPBuilder(apiRoot)
/**
* Endpoint: /contacts
* You can access the list of users who are in contact with you.
*/
def "Get your contact list"() {
when:
def response = http.get(path: contactsPath, headers: ["X-ChatWorkToken": apiToken])
def responseData = response.responseData
then:
println responseData
}
}
它總是拋出異常的下方。我不知道我在設置標題時出了什麼問題。
(當然這個API的工作對我來說,當我使用郵差)
消息:
groovyx.net.http.HttpResponseException: Bad Request
at groovyx.net.http.HTTPBuilder.defaultFailureHandler(HTTPBuilder.java:652)
at groovy.lang.Closure.call(Closure.java:414)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508)
at groovyx.net.http.HTTPBuilder.get(HTTPBuilder.java:292)
at groovyx.net.http.HTTPBuilder.get(HTTPBuilder.java:262)
at testcase.ChatworkApiSpec.Get your contact list(ChatworkApiSpec.groovy:24)
作爲作者,您隨時可以刪除問題。這是我建議你要做的。 – kriegaex
也許有人會有像我這樣的問題,我認爲它會幫助很多 –
那麼,你應該已經調整了標題的實際問題。我剛剛爲你做到了這一點。問題不在於如你所說設置標題。只要你有足夠的聲譽這樣做,請接受你自己的答案,以便結束這個問題。謝謝。 – kriegaex