【发布时间】:2018-10-19 12:20:02
【问题描述】:
出于某些测试目的,我尝试将加密变量从 angular 发送到 php 脚本。
这是客户端脚本:
ngOnInit(){
let user = "am";
let key = "pizza";
let enc = crypto.AES.encrypt(user, key);
console.log(enc);
let dec = crypto.AES.decrypt(enc, key);
console.log(dec.toString(crypto.enc.Utf8));
const headerOptions = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
const params = new HttpParams().set('name', enc)
this.http.post('aff.local/test.php', params, {
headers: headerOptions
}).subscribe(
res=>{
console.log(res)
},
error=>{
console.log( );
}
)
}
和 test.php 脚本:
<?php
error_reporting(E_ALL);
ini_set('log_errors', 0);
ini_set('display_errors', 1);
$host = "localhost";
$db = "dentist";
$user = "root";
$pass = "root";
$conn = new PDO("mysql:host={$host};dbname={$db};", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("SET CHARACTER SET utf8mb4");
$enc = $_POST['name'];
echo $enc;
?>
我在响应中有以下错误:
POST http://localhost:4200/aff.local/test.php 404(未找到)
在网络标签中:
Cannot POST /aff.local/test.php
该文件确实存在于虚拟主机文件夹中。
【问题讨论】:
-
您提供的 PHP 中没有任何内容会导致它输出 404。我们无法知道您的 HTTP 服务器为什么响应该 URL 的 404 错误。
-
那么,我们能提供什么帮助呢?端口可能有误,
aff.local的位置可能丢失,...... -
我需要发送给
aff.local/test.php而不是http://localhost:4200/aff.local/test.php -
你能通过地址栏访问你的文件(url)吗?
-
完成。解决方案:
http://aff.local/test.php而不是aff.local/test.php
标签: php angular angular5 vhosts