Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器不允许通过ssl连接使用POST方法_Ssl_Post_Server_Internet Explorer 11_Cloud Foundry - Fatal编程技术网

服务器不允许通过ssl连接使用POST方法

服务器不允许通过ssl连接使用POST方法,ssl,post,server,internet-explorer-11,cloud-foundry,Ssl,Post,Server,Internet Explorer 11,Cloud Foundry,我正在尝试对部署在关键PCF实例上的PHP脚本发出POST请求。我已经在PHP脚本中设置了基本头,以接受跨域请求。但是,当我从下面共享的html代码发出POST请求时,我看到发送的是GET请求而不是POST请求。在IE 11浏览器中,我得到SCRIPT7002:XMLHttpRequest:networkerror 0x2ef3,由于错误00002ef3错误,无法完成操作。另外,当我试图从Chrome浏览器发布数据时,我会看到下面的请求标题 Provisional headers are sho

我正在尝试对部署在关键PCF实例上的PHP脚本发出POST请求。我已经在PHP脚本中设置了基本头,以接受跨域请求。但是,当我从下面共享的html代码发出POST请求时,我看到发送的是GET请求而不是POST请求。在IE 11浏览器中,我得到
SCRIPT7002:XMLHttpRequest:networkerror 0x2ef3,由于错误00002ef3
错误,无法完成操作。另外,当我试图从Chrome浏览器发布数据时,我会看到下面的请求标题

Provisional headers are shown
Access-Control-Request-Headers: content-type
Access-Control-Request-Method: POST
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
服务器似乎不接受POST请求。我正在分享下面的服务器端PHP脚本和客户端html代码,以供参考。我不确定这是否与脚本、服务器端配置或SSL证书有关

我已经做了很多研究,也尝试了在不同帖子中提供的解决Stackoverflow类似问题的方法,但都没有效果

到目前为止,

方法1:使用PHP脚本 服务器端PHP脚本:

<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');
header('Method:' . $_SERVER['REQUEST_METHOD']);
$response = array(
    'status' => 0,
    'status_message' =>'Employee Addition Failed.'
);

if (isset($_POST) && !empty($_POST)) {
    if (!empty($_POST['username']) && !empty($_POST['credentials'])) {
        $response = array(
            'empid' => 123,
            'emp_name' =>'Some Name',
            'method' => 'POST'
        );
    }
}

if (isset($_GET) && !empty($_GET)) {
    $id = 0;
    if (isset($_GET['id']) && !empty($_GET['id'])) {
        $id = $_GET['id'];
    } 
    $response = array(
        'empid' => 123,
        'emp_name' =>'Some Name',        
        'method' => 'GET',
        'id' => $id,
        'method' => $_SERVER['REQUEST_METHOD'],
        'username' => $_POST['username'],
        'enable_post_data_reading' => ini_get('enable_post_data_reading')
    );    
}

header('Content-Type: application/json');
echo json_encode($response);
?>

客户端html:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#send").click(function(){
    $.ajax({
        url:"https://ui-php.apps.pcfdev.prod.demo.int/app/?id=1233",
        type:"POST",
        data:JSON.stringify({username:'Something', credentials: 'credentials'}),
        contentType:"application/json; charset=utf-8",
        dataType:"json",
        success: function(){
            console.log('Success');
        }
    });
  });
});
</script>
</head>
<body>
<button id="send">Send</button>
</body>
</html>

$(文档).ready(函数(){
$(“#发送”)。单击(函数(){
$.ajax({
url:“https://ui-php.apps.pcfdev.prod.demo.int/app/?id=1233",
类型:“POST”,
数据:JSON.stringify({username:'Something',credentials:'credentials'}),
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:函数(){
console.log('Success');
}
});
});
});
发送
当我从Chrome浏览器打电话时,我得到以下回应。

来自Chrome浏览器的响应标题:

当我从IE11浏览器拨打电话时,我看到浏览器会自动设置下面的标题,并且没有收到任何响应。

我在IE11浏览器的控制台中看到以下错误:

方法2: 当我尝试执行POST-curl请求时,我看到PHP脚本的GET块中的代码得到了执行。下面是curl请求的响应。


[注意:我已在浏览器中设置了代理,如果没有代理,我将无法访问PCF API]

如果查看浏览器中的开发工具,请查看“网络”选项卡并确认正在发送帖子。当您确认这一点时,您的Javascript(和浏览器)工作正常。此时,如果您的服务器端代码没有收到POST请求,那么浏览器和服务器之间的某些东西正在改变它(可能是代理或负载平衡器)。Cloud Foundry中的任何内容都不应修改您的请求方法。Gorouter不修改请求。PHP buildpack设置应用程序的方式也不应该这样做,至少不是有意的。一定要检查
cf日志
以确认。Gorouter和ApacheHttpd或Nginx(由PHP构建包设置)将编写访问日志,这些日志将告诉您他们观察到的HTTP方法。您可以使用它来跟踪更改发生的位置。