javascript - 添加 HTTP 表单后,Curl post 请求似乎不起作用
问题描述
我正在尝试使用 restful api 向我的 shadowsocks 服务器添加一个端口。
JS 代码获取站点的用户 id 并将其转换为 curl 代码
<script type="text/javascript">
function addUser() {
// Get user id
var div = document.getElementById("dom-target");
// Take user id text
var uid = div.textContent;
// Multiply by 1 to make sure JS thinks it's a number
var multiply = uid*1
// Generate password
var pass = Math.floor(Math.random() * 99999999999) + 10000000000 ;
// Generate port number
var port = 1024 + multiply;
// Change format to fit cURL
var curl = '{"port": ' + port + ',"password":"' + pass + '"}';
// Push to HTML
document.getElementById("curl").innerHTML = curl;
}
onload=addUser;
PHP 代码 - 当我只键入手动生成的代码 JS 脚本时,{"port": 1025,"password":"26909395438"}
它就可以工作。每当我把它变成一种形式时,它就会停止工作。
<?php
$curl = $_REQUEST['curl'];
$data = array('curl'=>$curl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://[ip]:4001/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer [token]";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//perform our request
$result = curl_exec($ch);
//show information regarding the request
print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' .
curl_error($ch);
?>
以及我发布 php 代码的 HTML 代码。
<p id="code"></p>
<form action="/create-beta.php" method="post">
<input type="hidden" name="curl" id="curl">
<br>
我是编码新手,我一直在互联网上进行挖掘以将其组合在一起。任何帮助将不胜感激。先感谢您。
解决方案
推荐阅读
- kubernetes - 如何通过命令行传递 pod 的数量
- quickfix - 在 QuickFix 中,RelatedSymGroup 设置的顺序是什么
- iframe - iframe 未加载提供的 URL
- android - 从 Koin 模块调用活动
- docker - 无法像在 Windows 控制台上运行一样在 bat 文件中运行命令
- regex - SED 在特定模式后替换 - 括号中的值
- angular - 角度错误为找不到路径控制:'_OSkilss -> 0 -> Imageuploade'
- c# - Visual Studio Code 中没有 C# 代码分析
- android - Unity Profiler - Android 设备上几乎 100% 的 PlayerLoop
- c# - 将 gRPC 服务绑定到 aspnetcore 中的特定端口