获取针对泽西客户端请求标头的错误?

时间:2014-11-25 06:15:41

标签: jersey clickatell

我需要通过jersey客户端为REST调用设置这些标头。 clickatell消息发送休息呼叫

curl -i \
            -X POST \
            -H "X-Version: 1" \
            -H "Content-Type: application/json" \
            -H "Authorization: Bearer Your Authorization Token" \
            -H "Accept: application/json" \

我的代码是:

Client client = Client.create();
WebResource webResource = client.resource("https://api.clickatell.com/rest/message");

ClientResponse response = webResource
                            .header("Authorization", "Bearer clickATellAuthKey")    
                            .header("X-Version", "1")
                            .header("Content-Type", "application/json")
                            .header("Accept", "application/json")
                            .post(ClientResponse.class, input); 

我收到此错误:

  

{ “错误”:{ “代码”: “001”, “描述”:“认证   失败”, “文档”: “http://www.clickatell.com/help/apidocs/error/001.htm”}}

文档说明未指定auth标头。该请求在Postman(chrome restful client extension)中使用相同的标题

正常工作

需要帮助。

2 个答案:

答案 0 :(得分:2)

1)你的标题似乎正在经历。如果不是,您将收到有关未设置版本标头的错误。

2)001错误表示您的身份验证令牌未指定或不正确。

3)我建议您复制并粘贴整个身份验证令牌,然后重试。注意_或。字符,因为它们是令牌的一部分。

答案 1 :(得分:0)

感谢@whatever_sa在代码中也需要一些改进,并且auth键存在问题,你的答案至少让我再次检查auth密钥。这是工作代码

    ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)                   
                        .header(MessageServices.API_AUTH_HEADER, MessageServices.AUTH_KEY)
                        .header(MessageServices.API_VERSION_HEADER, MessageServices.API_VERSION)                            
                        .post(ClientResponse.class, input);
相关问题