选项1:
$data= array(
"Code" => "abcde",
"Id" => "A007",
"RefNo" => "123456",
"UserName" => "QWE",
"UserEmail" => "qwe@gmail.com",
);
$url="https://testing.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($ch);
curl_close ($ch);
echo $result;
}
Run Code Online (Sandbox Code Playgroud)
选项2:
<form method="post" action="https://testing.php">
<input type="hidden" value="abcde" name="Code">
<input type="hidden" value="A007" name="Id">
<input type="hidden" value="QWE" name="UserName">
<input type="hidden" value="qwe@gmail.com" name="UserEmail">
<input type="hidden" value="123456" name="RefNo">
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
A和B之间有什么区别吗?因为我尝试了两者,但是curl只从api中获得“失败”响应。
因为它们都发送POST请求,所以没有什么区别,但是您可以说所用技术的唯一区别是:
您将面临的错误可能是由于请求中的数据丢失。或者您尝试访问其API的服务器上的IP地址未列入白名单。
另外,没有这样的URL https://testing.php,请尝试使用您的IP地址或完整的服务器地址来发送请求。