java - 无法为我的发帖请求提供用户名密码
问题描述
我是 Java 和 Vert.x 的新手
我正在尝试实现基本身份验证,以便我可以在发送发布请求之前登录远程服务器
我收到编译器错误。HttpRequest 类型的方法 basicAuthentication(String, String) 未定义我在做什么错。
package com.aexp.csrt.qs.cb.resources;
import com.aexp.csrt.qs.models.cb.passTrou.SourceQueryModel;
import io.vertx.reactivex.ext.web.RoutingContext;
import io.vertx.reactivex.core.Vertx;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.core.buffer.Buffer;
public class QueryExecutorFTS implements QueryExecutor {
private WebClient webClient;
@Override
public void executeQuery(SourceQueryModel Qm, RoutingContext rc) {
WebClientOptions options = new WebClientOptions().setMaxPoolSize(10).setConnectTimeout(5000)
.setVerifyHost(false);
JsonObject jreq = new JsonObject(Qm.getSourceQuery().getSourceDsl().getQuery());
Vertx vertx = rc.vertx();
webClient = WebClient.create(vertx.getDelegate(), options);
webClient
.basicAuthentication("myid", "mypassword")
.post(8094, "lpdospdb51079.phx.aexp.com", "/api/index/Text_search_name_idx/query")
.sendJsonObject(jreq,
ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
rc.response().setStatusCode(200).end(response.bodyAsString());
} else {
ar.cause().printStackTrace();
rc
.response()
.setStatusCode(500)
.setStatusMessage(ar.cause().getMessage())
.end();
}
})
;
}
}
解决方案
您的方法调用顺序不正确。
应该:
webClient
.post(8094, "lpdospdb51079.phx.aexp.com", "/api/index/Text_search_name_idx/query")
.basicAuthentication("myid", "mypassword")...
请注意,此 API 在3.5.3
. 您需要3.6.3
使用它:
https ://github.com/vert-x3/vertx-web/blame/5e54ad321b76eaeb4c19ca1706f2f90376a0534f/vertx-web-client/src/main/java/io/vertx/ext/web/客户端/HttpRequest.java#L159
推荐阅读
- python - 在 Python 中将递归函数更改为迭代函数
- emscripten - 如何设置基本的 C++/C 编译,然后为 emscripten 构建链接脚本
- python - 熊猫重复 groupby
- python - 熊猫数据框获取最后一个非零列的值
- internet-explorer-11 - 如何仅为 IE11 禁用内联脚本?
- android - 将变量从一个活动传递到另一个活动
- pandas - Pandas:使用来自另一个数据帧的数据过滤数据帧
- r - 给定 R 中列的条件,匹配两个数据框中的列
- tensorflow - 目前不支持 session_kwargs 中的一些键:%s', dict_keys(['learning_rate'])
- node.js - 我可以为两个或多个文件夹设置 nodejs viewengine 吗?