在js和php之间使用POST方法

问题描述 投票:0回答:0

我们目前正在开发一个 google chrome 扩展程序,该扩展程序可以阻止恶意 URL 并遇到 PHP 错误而无法解决。

不断弹出的错误是这样的:

Error Messegae

PHP 代码是这样的:

//clientServer.php
<?php

//Purpose - This file acts as a mediator between the client side popup.js and the server side test.py.
//It gets the HTML contents which acts as input to the suite of python files.
// This is a test

header("Access-Control-Allow-Origin: *");
$site=$_POST['url'];

$html = false;
if ($site) {
    $site = file_get_contents($site);
}
//$html = file_get_contents($site);
//echo file_get_contents($site);
//echo $html;
$bytes=file_put_contents('markup.txt', $html);

// Can use this if your default interpreter is Python 2.x.
// Has some problem executing 'which python2'. So, absolute path is just simpler.
//$python_path=exec("which python 2>&1 ");
//$decision=exec("$python_path test.py $site 2>&1 ");

// Replace the path with the path of your python2.x installation.

// C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10._3.10.2800.0_x64_qbz5n2kfra8p0\python3.10.exe
$decision=exec(" C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10._3.10.2800.0_x64_qbz5n2kfra8p0\python3.10.exe test.py $site 2>&1 ");
echo $decision;
?>

我们认为问题可能出在 POST 方法上,但无法弄清楚

还有问题的js代码是这样的:

var xhr=new XMLHttpRequest();
        params="url="+tablink;
        // alert(params);
        var markup = "url="+tablink+"&html="+document.documentElement.innerHTML;
        xhr.open("POST","http://localhost/Malicious-Web-Content-Detection-Using-Machine-Learning/clientServer.php",false);
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(markup);
        // Uncomment this line if you see some error on the extension to see the full error message for debugging.
        // alert(xhr.responseText);
        $("#div1").text(xhr.responseText);
        return xhr.responseText;

我们在网上找到的两个代码,因为我们从未使用过 php 或 js,目前丢失了,所以如果有人可以帮助我们,请非常感谢。

我们正在尝试使用js从浏览器获取URL并将其传递给php但是不断遇到这个错误消息

javascript php url google-chrome-extension xmlhttprequest
© www.soinside.com 2019 - 2024. All rights reserved.