小编Nop*_* 69的帖子

Java 无法解析“HttpResponse”中的方法“getEntity”

这些是我使用的导入:

import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.net.URIBuilder;
import java.net.URI;
Run Code Online (Sandbox Code Playgroud)

这是我制作的代码:

HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

Cannot resolve method 'getEntity' in 'HttpResponse'
Run Code Online (Sandbox Code Playgroud)

我尝试寻找解决方案,但它们都是针对 Android 的。我正在使用 Java,并且我使用 IntelliJ

此代码来自此示例:

    // // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org   /httpcomponents-client-ga/)

public class JavaSample 
{
   public static void main(String[] args) 
   {
     HttpClient httpclient = HttpClients.createDefault();

     try
     {
        URIBuilder builder = new URIBuilder("https://gateway.apiportal.ns.nl/reisinformatie-api/api/v2/departures");

        builder.setParameter("station", "{string}");
        builder.setParameter("uicCode", "{string}"); …
Run Code Online (Sandbox Code Playgroud)

java api

2
推荐指数
1
解决办法
3447
查看次数

标签 统计

api ×1

java ×1