我正在尝试简单地访问端点并使用 asString() 方法获取响应主体和 HttpResponse。代码可以编译,但在运行时会出错,说没有这样的方法错误。
我将 Unirest 导入到我的 Maven 构建中,并且我一直在关注这里的文档
HttpResponse<String> response = Unirest.get("http://mywebsite/post") .basicAuth("myapiuser", "mypassword") .asString();
这是堆栈跟踪:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.config.RequestConfig$Builder.setNormalizeUri(Z)Lorg/apache/http/client/config/RequestConfig$Builder; at kong.unirest.apache.DefaultFactory.tryNormalize(DefaultFactory.java:47) at kong.unirest.apache.DefaultFactory.apply(DefaultFactory.java:42) at kong.unirest.apache.DefaultFactory.apply(DefaultFactory.java:32) at kong.unirest.apache.RequestPrep.getHttpRequestBase(RequestPrep.java:88) at kong.unirest.apache.RequestPrep.prepare(RequestPrep.java:69) at kong.unirest.apache.ApacheClient.request(ApacheClient.java:122) at kong.unirest.BaseRequest.asString(BaseRequest.java:177) at com.ideiio.testdataloader.TestDataLoader.testRestGet(TestDataLoader.java:62) at com.ideiio.testdataloader.TestDataLoader.main(TestDataLoader.java:34)
我无法确定这是否只是我缺少依赖项的问题(我对 Maven 很陌生)或者代码本身是否有问题(尽管 Unirest 调用几乎是文档的精确副本) .
慕虎7371278
喵喔喔
相关分类