具有以“http://”开头的URL的站点是否可能?使用HTTPS协议 [英] Is it possible for a site having URL starting with "http://" using HTTPS protocol

查看:187
本文介绍了具有以“http://”开头的URL的站点是否可能?使用HTTPS协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个站点,其网址以http://开头,但这给了我一个例外消息 - 不支持的协议:https。该网站是否可能使用HTTPS协议,其URL仍以http://开头,而不是https://。

I have a site whose URL starts with "http://" but that is giving me an exception with the message - Unsupported protocol: https. Is it possible that the site is using HTTPS protocol still its URL is starting with "http://" and not "https://".

public ActionForward executeAction(ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    ActionForward forward = mapping.findForward(Constants.SUCCESS);
    String link = "http://abc.fgh.jkl.mno";
    URL thisURL;
    HttpURLConnection conn = null;
    try {
        thisURL = new URL(link);
        conn = (HttpURLConnection) thisURL.openConnection();
        System.out.println(conn.getResponseCode());
        System.out.println(conn.getResponseMessage());
        } catch (Exception ex) {
        ex.printStackTrace();
    }
    return forward;
}       

堆栈跟踪

java.net.ProtocolException: Unsupported protocol: https'
    at weblogic.net.http.HttpClient.openServer(HttpClient.java:342)
    at weblogic.net.http.HttpClient.New(HttpClient.java:238)
    at weblogic.net.http.HttpURLConnection.connect(HttpURLConnection.java:172)
    at weblogic.net.http.HttpURLConnection.followRedirect(HttpURLConnection.java:643)
    at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:422)
    at           weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:36)
    at weblogic.net.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:947)
    at com.cingular.cscape.da.struts.action.thisAction.executeAction(thisAction.java:56)
    at com.cingular.cscape.da.struts.action.BaseAction.execute(BaseAction.java:300)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:53)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Unknown Source)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)                  


推荐答案

您是否注意到异常消息中的不匹配撇号?

Did you notice the unmatched apostrophe in the exception message?

java.net.ProtocolException: Unsupported protocol: https'
                                                       ^

更新:看起来这个撇号只是WebLogic HttpClient如何打印此异常的一个怪癖。

Update: looks like this apostrophe is just a quirk of how the WebLogic HttpClient prints this exception.

确定了Asker的根本问题在聊天会话中:他正在访问一个http:// URL,将他重定向到https:// URL。该https地址的Web服务器正在提供他的JRE / HttpClient不信任的证书。

Asker's root problem was identified in a chat session: he's accessing an http:// URL that redirects him to an https:// URL. The webserver at that https address is serving up a certificate that his JRE/HttpClient does not trust.

实际的异常应该是SSLKeyException。我认为WebLogic HttpClient错误地将此问题误报为不受支持的协议问题。我认为核心问题是:

The actual exception should be a SSLKeyException. I think the WebLogic HttpClient is misreporting this problem as an unsupported protocol issue. I think the core issue is:

<警告> <安全和GT; < BEA-090477> javax.net.ssl.SSLKeyException:[安全:090477]从www.X.com收到证书链 - nnn.nnn.nnn.nnn不受信任导致SSL握手失败。

这是Asker在直接访问https:// URL时看到的消息(而不是通过重定向链)。

This is the message that the Asker sees when accessing the https:// URL directly (instead of through a redirect chain).

默认情况下,Java的Http [s] URLConnection会自动且安静地跟踪重定向。如果您对重定向到的位置感到好奇,请尝试以下代码:

By default Java's Http[s]URLConnection follows redirects automatically and quietly. If you are curious about where you are being redirected to, try this code:

connection.setInstanceFollowRedirects(false);
String location = connection.getHeaderField("Location");
System.out.println("Redirected to: " + location);

请注意,您重定向到的网址也可能会将您重定向到其他地方以及其他地方,直至 http.maxRedirects 次。重定向可能以这种方式链接。如果他们确实链接,您将需要继续关注重定向,直到您找到不发出重定向的网址。这就是当 setInstanceFollowRedirects(true)时,URL连接最终确定的地方。

Note that the URL you get redirected to may also redirect you somewhere else and on and on, up to http.maxRedirects times. Redirects may "chain" in this way. If they do chain, you will need to keep following the redirects until you reach a URL that does not issue a redirect. That is where the URL connection eventually finalizes when setInstanceFollowRedirects(true).

另外,我在sun中找到了一些代码.net.www.protocol.http.HttpURLConnection似乎表明 HttpURLConnection可能不支持切换协议(HTTP - > HTTPS)作为其遵循逻辑的自动重定向的一部分

Also, I found some code in sun.net.www.protocol.http.HttpURLConnection that seems to indicate that HttpURLConnection may not support switching protocols (HTTP -> HTTPS) as part of its automatic redirect following logic:

private boolean followRedirect() throws IOException {
    // ... [snip] ...
    if (!url.getProtocol().equalsIgnoreCase(locUrl.getProtocol())) {
        return false;
    // ... [snip] ...

WebLogic有自己的(不同的)HttpURLConnection的实现,但它可能包含类似的逻辑以防止协议切换。因此,即使Asker解决了他的证书信任问题,他仍然可能无法使用HttpURLConnection自动遵循从HTTP到HTTPS的重定向链。解决方法是使用 setInstanceFollowRedirects(false)并手动关注重定向。或直接访问HTTPS站点。

WebLogic has its own (different) implementation of HttpURLConnection, but it may contain similar logic to prevent protocol switching. So, even if the Asker resolves his certificate trust issues, he still may not be able to use HttpURLConnection to automatically follow a redirect chain that goes from HTTP to HTTPS. A workaround would be to use setInstanceFollowRedirects(false) and follow redirects manually. Or access the HTTPS site directly.

这篇关于具有以“http://”开头的URL的站点是否可能?使用HTTPS协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆