添加HTTP表单后,卷曲发布请求似乎不起作用

时间:2018-08-23 13:25:20

标签: javascript php rest api curl

我正在尝试使用宁静的api向我的shadowsocks服务器添加端口。

JS代码获取网站的用户ID,并将其转换为curl代码

~/.bin

PHP代码-当我只键入手动生成的代码JS脚本<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; 时,它可以工作。每当我将其转换为表单时,它就会停止工作。

{"port": 1025,"password":"26909395438"}

和发布php代码的HTML代码。

<?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);
?>

    

我是编码的新手,我一直在互联网上进行挖掘以将其组合在一起。任何帮助将不胜感激。预先谢谢你。

0 个答案:

没有答案