AngularJS $ http返回ERR_SSL_VERSION_OR_CIPHER_MISMATCH
我从昨天起就开始研究这个问题而且情况变得更糟了。之前我能够发送POST消息而不是GET,现在我无法做任何一个。 。
代码: AngularJS Postmethod(我想在数据库中插入一个条目)
$scope.submitReport = function(){
if (typeof($scope.errorReport.numberPlate) == 'undefined'|| typeof($scope.errorReport.brief) == 'undefined' )
return;
if (typeof($scope.errorReport.imgUri) != 'undefined') console.log("img is defined");
var request = $http({
method: "post",
url: "http://ekstroms.xyz/motabVerkstad/api.php",
crossDomain : true,
data: JSON.stringify({
numberPlate: $scope.errorReport.numberPlate,
brief: $scope.errorReport.brief,
imgUri: $scope.errorReport.imgUri
}),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
/* Successful HTTP post request or not */
request.success(function(data) {
console.log(data);
});
};
代码:AngulasJS GET方法(我想从数据库中检索所有条目)
$scope.$on('$ionicView.enter', function(e) {
var request = $http({
method: "GET",
url: "http://ekstroms.xyz/motabVerkstad/api.php" // URL to file
// ,cache: true // Will enable once I get it to work
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log('callback data->'+response.data);
console.log('callback status'+response.status);
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log('callback data->'+response.data);
console.log('callback status->'+response.status);
console.log(response);
});
});
代码:PHP(http://ekstroms.xyz/motabVerkstad/api.php)
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
//http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$brief = $request->brief;
$numberPlate = $request->numberPlate;
$imgUri = $request->imgUri;
if ($brief != "") {
echo "Server returns: " . $brief;
}
else {
echo "Empty brief parameter!";
}
// Connect to database
include 'connect.php';
$db = Database::getInstance();
$db->connect();
// Prepare SQL query
$sql = "INSERT INTO `felrapporter`(`number_plate`, `brief`, `photo`)
VALUES ('".$numberPlate."','".$brief."','".$imgUri."')";
// Request the query
echo $db->question($sql);
}
else {
echo "Not called properly with brief parameter!";
}
}
else if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Connect to database
include 'connect.php';
$db = Database::getInstance();
$db->connect();
// $sql = "SELECT * FROM Articles order by Date desc";
$sql = "SELECT * FROM `felrapporter`;";
$stmt = $db->question($sql);
$stmt->setFetchMode(PDO::FETCH_CLASS, 'register');
// foreach($stmt as $entry) {
// $entry->returnArray();
// }
echo json_encode('hej');
// echo $stmt;
// $test = $db->question($sql);
// $numberPlate = 'a';
// $brief = 'b';
// $imgUri ='';
// if ($test) $db->question("INSERT INTO `felrapporter`(`number_plate`, `brief`, `photo`)
// VALUES ('".$numberPlate."','".$brief."','".$imgUri."')";)
// echo $test;
}
?>
数据库结构:
CREATE DATABASE motab_verkstad;
USE motab_verkstad;
CREATE TABLE Felrapporter
(
id int NOT NULL PRIMARY KEY AUTO_INCREMENT,
number_plate varchar(32) NOT NULL,
brief varchar(2048) NOT NULL,
date DATETIME,
photo varchar(255)
);
ALTER TABLE `felrapporter` CHANGE `date` `date` DATETIME NULL DEFAULT CURRENT_TIMESTAMP;
Chrome:GET的结果如下:
callback data->null
callback status->0
Object {data: null, status: 0, config: Object, statusText: ""}
GET https://ekstroms.xyz/motabVerkstad/api.php net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH ekstroms.xyz/motabVerkstad/api.php:1
Chrome:POST结果
POST https://ekstroms.xyz/motabVerkstad/api.php net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH ekstroms.xyz/motabVerkstad/api.php:1
Firefox:POST结果 很多东西......这个,它在这里工作正常
Firefox:POST结果 没什么..
Apache:error.log的子集
[Sat Jan 30 02:23:48.099594 2016] [:error] [pid 8520:tid 1708] [client 80.244.89.57:4129] PHP Notice: Undefined property: stdClass::$imgUri in C:\\xampp\\htdocs\\motabVerkstad\\api.php on line 12, referer: http://localhost:8100/
[Sat Jan 30 02:23:48.100594 2016] [:error] [pid 8520:tid 1708] [client 80.244.89.57:4129] PHP Fatal error: Uncaught Error: Call to a member function query() on null in C:\\xampp\\htdocs\\motabVerkstad\\connect.php:32\nStack trace:\n#0 C:\\xampp\\htdocs\\motabVerkstad\\api.php(31): Database->question('INSERT INTO `fe...')\n#1 {main}\n thrown in C:\\xampp\\htdocs\\motabVerkstad\\connect.php on line 32, referer: http://localhost:8100/
[Sat Jan 30 02:26:10.718658 2016] [core:error] [pid 8520:tid 1688] [client 80.244.89.57:4176] AH00082: an unknown filter was not added: DEFLATE
[Sat Jan 30 02:26:10.719658 2016] [:error] [pid 8520:tid 1688] [client 80.244.89.57:4176] PHP Notice: Undefined property: stdClass::$imgUri in C:\\xampp\\htdocs\\motabVerkstad\\api.php on line 12, referer: http://localhost:8100/
[Sat Jan 30 02:26:10.728667 2016] [:error] [pid 8520:tid 1688] [client 80.244.89.57:4176] PHP Fatal error: Uncaught Error: Call to a member function query() on null in C:\\xampp\\htdocs\\motabVerkstad\\connect.php:32\nStack trace:\n#0 C:\\xampp\\htdocs\\motabVerkstad\\api.php(31): Database->question('INSERT INTO `fe...')\n#1 {main}\n thrown in C:\\xampp\\htdocs\\motabVerkstad\\connect.php on line 32, referer: http://localhost:8100/
仅供注意事项..
不确定还有什么要提的..我希望我已经很好地描述了我的结构,代码和问题。
要点: Firefox可以执行$ http发布请求 Chrome无法执行$ http post或$ http get请求 我得到的另一个可能无关紧要的问题是firefox也给了我这个错误:
The connection to ws://localhost:35729/livereload was interrupted while the page was loading.