gpt4 book ai didi

java - 如何使用pact-jvm-provider-junit + http basic auth + Eclipse TPC/IP Monitor?

转载 作者:行者123 更新时间:2023-12-02 12:29:21 24 4
gpt4 key购买 nike

我想做这样的事情:

private static final String protocol = "http";

// host verification via http basic auth, http://username:passwort@url ...
private static final String host = "http://username:password@myservice.com";
private static final int port = 80;

private static final String path = "/";

@TestTarget
public final Target target = new HttpTarget(protocol, host, port, path);

问题是:我想通过 TCP/IP 监视器分析我的连接,但它似乎没有机会使用 http 基本身份验证。如何使用 http 基本身份验证通过 TCP/IP 监视器转发连接?

我可以为每个 header 设置必要的参数吗?也许是这样的:

@TargetRequestFilter
public void exampleRequestFilter(HttpRequest request) {
request.addHeader("Authorization", "OAUTH hdsagasjhgdjashgdah...");
}

或者还有其他选项如何使用 http basic auth + TCP/IP Monitor?

提前致谢!

最佳答案

在 Junit 5 中,这样做的方式与 here 不同。 :

    @TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void testTemplate(PactVerificationContext context, HttpRequest request) {
// This will add a header to the request
request.addHeader("X-Auth-Token", "1234");
context.verifyInteraction();
}

关于java - 如何使用pact-jvm-provider-junit + http basic auth + Eclipse TPC/IP Monitor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45354442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com