0

我需要通过 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 ”}}

该文件说未指定身份验证标头。该请求在具有相同标头的 Postman(chrome restful 客户端扩展)中运行良好

需要帮忙。

4

2 回答 2

2

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

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

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

于 2014-11-25T11:09:38.897 回答
0

谢谢@whatever_sa,代码中还需要一些改进,而且身份验证密钥也存在问题,您的回答至少让我再次检查身份验证密钥。这是工作代码

    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);
于 2014-11-25T11:30:58.550 回答