Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过简单的html表单使用php发送CURL代码_Php_Curl - Fatal编程技术网

如何通过简单的html表单使用php发送CURL代码

如何通过简单的html表单使用php发送CURL代码,php,curl,Php,Curl,我有这个CURL代码&我需要使用php发送带有输入数据的代码 卷曲代码: curl -H "Content-Type: application/json" -d '{"apiKey": "43wrxxxxxxxxxxxxxxx", "message":"MessageValue", "title":"TitleValue", "platform":"android", "publicKey": "wxxxx", "live": "false"}' https://push.xxxxx.io/ap

我有这个CURL代码&我需要使用php发送带有输入数据的代码

卷曲代码:

curl -H "Content-Type: application/json" -d '{"apiKey": "43wrxxxxxxxxxxxxxxx", "message":"MessageValue", "title":"TitleValue", "platform":"android", "publicKey": "wxxxx", "live": "false"}' https://push.xxxxx.io/api/send
我需要在代码中添加消息标题,然后使用php发送代码

示例表格:

<html>
<head><title>Test Form</title></head>

<body>
<form action="server.php" method="post">
  Message: <input type="text" name="message"><br>
  Title: <input type="text" name="title"><br>
  <input type="submit" value="Submit">
</form>

</body>

</html>

测试表
信息:
标题:
如何使用PHP


谢谢大家!

您可以通过AJAX提交数据,并在服务器端PHP脚本上处理数据
<?php
if(isset($_POST['Submit']){
$ch = curl_init( 'https://push.xxxxx.io/api/send');
$data=array('api_key'=>'43wrxxxxxxxxxxxxxxx','message'=>$_POST['message']);//You can enter more data
$payload = json_encode( $data );//encode data to json
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
}else{
die('error'); // invalid entry
}
?>