使用Apache HttpClient进行API令牌身份验证

时间:2016-09-21 17:09:04

标签: java api authentication token

有没有人知道如何使用Apache HttpClient使用api令牌对用户进行身份验证?我能够连接到我的api,但是我得到了一个"无法验证你"错误。

这是我的代码

public static void main (String[] args) throws Exception
{
  HttpClient client;
  client = HttpClientBuilder.create().build();
  HttpGet request = new HttpGet("MY WORKING HTTPS URL IS HERE");
  HttpResponse response = client.execute(request);
  BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  String http_line = " ";

  while((http_line = rd.readLine()) != null)
  {
     System.out.println(http_line);
  }

}

我的api会抛出这个

<errors>
<error>Couldn't authenticate you</error>
</errors>

我的输出控制台给了我这个错误

log4j:WARN没有为logger找到appender(org.apache.http.client.protocol.RequestAddCookies)。

log4j:WARN请正确初始化log4j系统。

log4j:WARN有关详细信息,请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig

ALSO 我应该使用除HttpClient以外的其他内容,因为我的网址是&#34; https://&#34;而不是&#34; http://&#34;?我使用的是NetBeans IDE 8.1(iOS)。

任何帮助将不胜感激。提前谢谢。

0 个答案:

没有答案