0

我正在使用演示实例来查询 service-now。使用 cURL 可以正常工作,但我想使用 java 来查询 Table API。我遵循了这个。我已正确提供了我的实例凭据和实例名称。我收到这样的错误:

$ javac GetAction.java
GetAction.java:6: error: package org.apache.http does not exist
import org.apache.http.HttpException;
                      ^
GetAction.java:7: error: package org.apache.http does not exist
import org.apache.http.HttpHost;
                      ^
GetAction.java:8: error: package org.apache.http.auth does not exist
import org.apache.http.auth.AuthScope;
                           ^
GetAction.java:9: error: package org.apache.http.auth does not exist
import org.apache.http.auth.UsernamePasswordCredentials;
                           ^
GetAction.java:10: error: package org.apache.http.client does not exist
import org.apache.http.client.CredentialsProvider;
                             ^
GetAction.java:11: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.CloseableHttpResponse;
                                     ^
GetAction.java:12: error: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpGet;
                                     ^
GetAction.java:13: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.BasicCredentialsProvider;
                                  ^
GetAction.java:14: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.CloseableHttpClient;
                                  ^
GetAction.java:15: error: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.HttpClients;
                                  ^
GetAction.java:16: error: package org.apache.http.util does not exist
import org.apache.http.util.EntityUtils;
                           ^
GetAction.java:19: error: cannot find symbol
        public static void main(String[] args) throws IOException, HttpException {
                                                                   ^
  symbol:   class HttpException
  location: class GetAction
GetAction.java:24: error: cannot find symbol
        public void getRequest() throws HttpException, IOException {
                                        ^
  symbol:   class HttpException
  location: class GetAction
GetAction.java:25: error: cannot find symbol
                CredentialsProvider credsProvider = new BasicCredentialsProvider();
                ^
  symbol:   class CredentialsProvider
  location: class GetAction
GetAction.java:25: error: cannot find symbol
                CredentialsProvider credsProvider = new BasicCredentialsProvider();
                                                        ^
  symbol:   class BasicCredentialsProvider
  location: class GetAction
GetAction.java:27: error: cannot find symbol
                new AuthScope(new HttpHost("xxxxxxxx.service-now.com")),
                    ^
  symbol:   class AuthScope
  location: class GetAction
GetAction.java:27: error: cannot find symbol
                new AuthScope(new HttpHost("xxxxxxxx.service-now.com")),
                                  ^
  symbol:   class HttpHost
  location: class GetAction
GetAction.java:28: error: cannot find symbol
                new UsernamePasswordCredentials("wwwww", "yyyyyy"));
                    ^
  symbol:   class UsernamePasswordCredentials
  location: class GetAction
GetAction.java:29: error: cannot find symbol
        CloseableHttpClient httpclient = HttpClients.custom()
        ^
  symbol:   class CloseableHttpClient
  location: class GetAction
GetAction.java:29: error: cannot find symbol
        CloseableHttpClient httpclient = HttpClients.custom()
                                         ^
  symbol:   variable HttpClients
  location: class GetAction
GetAction.java:34: error: cannot find symbol
            HttpGet httpget = new HttpGet("https://xxxxxxxx.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000057&sysparm_limit=1");
            ^
  symbol:   class HttpGet
  location: class GetAction
GetAction.java:34: error: cannot find symbol
            HttpGet httpget = new HttpGet("https://xxxxxxxx.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000057&sysparm_limit=1");
                                  ^
  symbol:   class HttpGet
  location: class GetAction
GetAction.java:37: error: cannot find symbol
            CloseableHttpResponse response = httpclient.execute(httpget);
            ^
  symbol:   class CloseableHttpResponse
  location: class GetAction
GetAction.java:41: error: cannot find symbol
                String responseBody = EntityUtils.toString(response.getEntity());
                                      ^
  symbol:   variable EntityUtils
  location: class GetAction
24 errors

如何使文档代码工作?任何帮助将不胜感激。

4

1 回答 1

0

该错误表示上述依赖项不存在。您需要为 package 添加 jar 文件org.apache.http。如果您使用的是 maven,您可以从这里获取库。

于 2018-10-12T04:56:18.593 回答