简体   繁体   English

从https网站发送请求

[英]Send request from https web site

i'm using apache tomcat 8 with spring mvc . 我正在using apache tomcat 8带有spring mvc using apache tomcat 8 i'm executing a script with tampermonkey on a external web site runing on https protocol. 我在运行https协议的外部网站上使用tampermonkey执行脚本。

    ....
    $.ajax({ 
        url     : 'http://localhost:8080/getfromFoo'  ,  type : 'post', 
        success : function(data) {},        
        error   : function(){ alert("error"); }
    });     

I got in chrome : 我有铬:

Mixed Content: The page at 
'https://www.foo.com/' 
was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 
'http://localhost:8080/getfromFoo'. 
This request has been blocked; the content must be served over HTTPS.

and when I change in ajax url to https like this url : 'https://localhost:8080/getfromFoo' to https 当我将ajax url更改为https如下所示url : 'https://localhost:8080/getfromFoo'更改为https

in chrome : 在chrome中:

POST https://localhost:8080/getfromFoo net::ERR_SSL_PROTOCOL_ERROR
XHR failed loading: POST "https://localhost:8080/getfromFoo".

i got in apache tomcat log : 我进入了apache tomcat日志:

nov. 20, 2015 12:31:41 PM org.apache.coyote.http11.AbstractHttp11Processor process
INFOS: Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

The external website is in https and yours isnt, If you are going to do a request to https then you should make the request from https. 外部网站位于https而不是您的网站,如果您要向https请求,则应从https发出请求。 Basically what i mean is switch your tomcat to https. 基本上我的意思是将您的tomcat切换为https。 if using spring-boot with spring mvc it is really simple just generate a certifciate and add it to the properties like this. 如果将spring-boot与spring mvc一起使用,则非常简单,只需生成一个证书并将其添加到这样的属性中即可。

server.port:8443
    server.ssl.key-store: keystore.p12
    server.ssl.key-store-password: somepass
    server.ssl.keyStoreType: PKCS12
    server.ssl.keyAlias: tomcat

Hope it helps 希望能帮助到你

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM