java api html_Java API修改html返回

HY,

我即将更改以下代码的一小部分:#

private void processRequest(final HttpServerExchange exchange) throws IOException {

final ChannelInputStream cis = new ChannelInputStream(exchange.getRequestChannel());

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");

final long beginningTime = System.currentTimeMillis();

final String body = IOUtils.toString(cis, StandardCharsets.UTF_8);

final AbstractResponse response;

if (!exchange.getRequestHeaders().contains("X-IOTA-API-Version")) {

response = ErrorResponse.create("Invalid API Version");

} else if (body.length() > maxBodyLength) {

response = ErrorResponse.create("Request too long");

} else {

response = process(body, exchange.getSourceAddress());

}

sendResponse(exchange, response, beginningTime);

}来源:https://github.com/iotaledger/iri/blob/dev/src/main/java/com/iota/iri/service/API.java

普通答案,如果你打开一个Borwser的Endpoint看起来像这样:

{"error":"Invalid API Version","duration":0}我的目标是修改仅用于浏览器的答案(即如果您未指定IOTA-API Versio标题的情况),将其转换为简短的html答案,如:

你好世界,你在blabla。

可悲的是,我对Java很不好,从来没有工作,我最后的尝试是:

private void processRequest(final HttpServerExchange exchange) throws IOException {

final ChannelInputStream cis = new ChannelInputStream(exchange.getRequestChannel());

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");

final long beginningTime = System.currentTimeMillis();

final String body = IOUtils.toString(cis, StandardCharsets.UTF_8);

final AbstractResponse response;

final String htmlout = "0";

if (!exchange.getRequestHeaders().contains("X-IOTA-API-Version")) {

final String htmlout = "

Welcome

>/center>";

} else if (body.length() > maxBodyLength) {

response = ErrorResponse.create("Request too long");

} else {

response = process(body, exchange.getSourceAddress());

}

if (htmlout.contains("html")) {

sendResponse(htmlout);

} else {

sendResponse(exchange, response, beginningTime);

}

}抛出几个错误...

从maven图像码头化构建时引发的错误:

[ERROR] /iri/src/main/java/com/iota/iri/service/API.java:[171,26] variable htmlout is already defined in method processRequest(io.undertow.server.HttpServerExchange)

[ERROR] /iri/src/main/java/com/iota/iri/service/API.java:[178,13] method sendResponse in class com.iota.iri.service.API cannot be applied to given types;BR

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值