Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set http headers for authentication #74

Open
zcmgyu opened this issue Apr 11, 2017 · 1 comment
Open

Can't set http headers for authentication #74

zcmgyu opened this issue Apr 11, 2017 · 1 comment

Comments

@zcmgyu
Copy link

zcmgyu commented Apr 11, 2017

Http-builder: 0.7.1
Language: Groovy
Framework: Spock

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
    }
}

It always throws below exception. I don't know what i was wrong with setting headers.
(Of course this api works for me when I use Postman)

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)

@zcmgyu
Copy link
Author

zcmgyu commented Apr 11, 2017

Sorry my bad question. I release that my root link also included path in it.

Replace:

def apiRoot = "http://api.chatwork.com/v2"
def contactsPath = "/contacts"

by

def apiRoot = "http://api.chatwork.com"
def contactsPath = "/v2/contacts"

can resolve this problem.

Please close this issue. Thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant