泽西客户端 v 2

Jersey Client v 2

我有一个网站,我只想编写一个脚本来将字符串发送到页面上的文本输入(唯一一个),然后单击提交。 我构建了一个 selenium,但有人告诉我这太过分了 "easier" 访问页面上的端点并以这种方式发送文本。

有人建议我为此使用 Jersey 客户端。

import org.glassfish.jersey.client.*;
import org.glassfish.jersey.client.JerseyWebTarget;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.WebTarget; 
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.JerseyClientBuilder;

public class mqDirect {

public static void main (String args[])
{

    String baseUrl = "URL";   // removed real url herebut it is properlink
    Client client = JerseyClientBuilder.createClient();

    WebTarget target = client.target(baseUrl);
    Response response = target.request().get();

    System.out.print("response is : " + response);

 }
}

我一直在查看示例并编译此代码,但我只是想看看在这种情况下的实际响应是什么,当我 运行 它时,我得到错误

Exception in thread "main" java.lang.IllegalStateException: InjectionManagerFactory not found. atorg.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManag erFactory[=11=](Injections.java:98) at java.util.Optional.orElseThrow(Optional.java:290)

所以要将文本字符串发送到页面上的文本输入,我是否使用 .post() 方法? 我觉得 selenium 在这方面要容易得多,如果不是那么漂亮的话......

我使用了依赖项:

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.16</version>
        </dependency>

它工作正常:
也许你应该改变你的依赖版本。
希望对你有帮助:)