读取超文本传输​​协议(HTTP或HTTPS)

时间:2011-06-07 06:58:53

标签: http url https

我想阅读用户所在的协议。 HTTP或HTTPS并相应地在该页面上为站点2构建我的URL。

第1步:Read the url user is on site 1 //可以是http或https

第2步:Prefix the protocol for site 2 on that site 1 page according. HTTP or HTTPS as per step 1

FF处理得很好。但IE不允许从HTTPS站点导航到HTTP站点。

   <a href="protocol://site2.com/">Click here for site 2</a>

3 个答案:

答案 0 :(得分:6)

从我的jsp中,我能够将URL分成几部分。例如,https://test.com:8080/将产生:

request.getScheme() = https
request.getServerName() = test.com
request.getServerPort() = 443

有关详细信息,请参阅this document

答案 1 :(得分:1)

您尝试使用哪种语言?

对于JavaScript,有parent.location.protocol

对于PHP,您可以尝试使用$_SERVER['SERVER_PORT'] == 443甚至$_SERVER['HTTPS']

答案 2 :(得分:1)

我在JSP中使用String scheme = request.getScheme();做了