简体   繁体   English

HttpHandler无法处理HTTP请求

[英]HttpHandler fails to handle http requests

I'm trying to build https proxy server using com.sun.net.httpServer.* library. 我正在尝试使用com.sun.net.httpServer。*库构建https代理服务器。 when I'm defining the server context as follows: 当我如下定义服务器上下文时:

httpServer.createContext("/test", new MyHandler());

and I open from a browser the url: " https://localhost:443/test " it works as expected, but when the server context is defined this way: 并且我从浏览器中打开了URL:“ https:// localhost:443 / test ”,它可以按预期工作,但是以这种方式定义服务器上下文时:

httpServer.createContext("/", new MyHandler());

I notice that my handler is not being used when I enter a URL like: " https://www.google.co.il/ " 我注意到当我输入类似“ https://www.google.co.il/ ”的URL时,没有使用我的处理程序。

What am I missing? 我想念什么?

This line will only change the context path, not the server URL. 该行将仅更改上下文路径,而不更改服务器URL。

httpServer.createContext("/", new MyHandler());

So for this context, you will get a response at this URL - " https://localhost:443/ ". 因此,对于这种情况,您将在以下URL处获得响应-“ https:// localhost:443 / ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:如何处理/解析传入的HTTP请求? - Java: how to handle/parse incoming HTTP requests? Servlet处理小程序通信和HTTP请求 - Servlet to handle both applet communication and http requests 如果HTTP请求之一失败,JMeter发送电子邮件 - JMeter sending email if one of the HTTP requests fails 如何处理具有许多无效URL的代理HTTP请求 - How should I handle proxying HTTP requests with many invalid URLs 单个服务器每秒处理2000个HTTP请求是否现实? - Is it realistic for a single server to handle 2000 HTTP requests per second? 如何使用 java.net.URLConnection 来触发和处理 HTTP 请求 - How to use java.net.URLConnection to fire and handle HTTP requests Spring MVC控制器如何处理多个长HTTP请求? - How Spring MVC controller handle multiple long http requests? 如何使用 webflux 在 Spring Boot 2 中处理 HTTP OPTIONS 请求? - How to handle HTTP OPTIONS requests in Spring Boot 2 with webflux? AsyncTaskLoader用于处理方向更改的http请求,使用泛型,继承 - AsyncTaskLoader for http requests to handle orientation changes, using generics, inheritance 如何执行异步计算并同时处理其他http请求? - How to execute async calculation and handle other http requests at the same time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM