2014-11-25 64 views
0

我需要通过泽西客户端为REST调用设置这些标头。 的Clickate消息发送REST调用针对平针织客户端请求标头的错误?

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); 

我收到此错误:

{"error":{"code":"001","description":"Authentication failed","documentation":" http://www.clickatell.com/help/apidocs/error/001.htm "}}

文件说没有指定AUTH头。该请求工作正常在邮递员(铬平安客户端扩展)具有相同的标题

需要帮助。

回答

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); 
2

1)您的标题似乎正在经历。如果他们不是,你会得到一个关于不设置版本标题的错误。

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

3)我建议你复制并粘贴你的整个认证令牌,然后重试。小心_或。字符,因为它们是令牌的一部分。