简体   繁体   中英

Jsoup method header(String, String) is undefined for the type Connection.KeyVal

I am using Jsoup Version 1.9.2 and have the following code:

 public static String reQuest(String tUri, org.jsoup.Connection.Method Met, String postData) throws IOException {
    Response res = null;

    try {
      res = Jsoup.connect( tUri )
              .ignoreContentType( true )
              .followRedirects( true )
              .cookies( HandleSession.COOKIES )
        .data( postData )
        .header( "X-Requested-With", "XMLHttpRequest" )
        .method( Met )
        .timeout( 10000 )
        .execute();
      Util.log.finest( tUri );
    }
    catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return res == null ? null : res.body();
  }

The error is in this line:

.header( "X-Requested-With", "XMLHttpRequest" )

it says:

The method header(String, String) is undefined for the type Connection.KeyVal

but jsoup documentation says, that this method is available with this parameters:

https://jsoup.org/apidocs/org/jsoup/Connection.Response.html

I already used exactly this code with a former version of jsoup.

What is wrong with it?

In Jsoup 1.9.2 the request body has to be set by using .requestBody instead of .data. Im so sorry, did not see it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM