PHP 数字提交表单并自动访问接口




<?php
	if(isset($_POST['number']) && isset($_POST['api_url'])) {
		$number = $_POST['number'];
		$api_url = $_POST['api_url'];

		// 构造请求参数
		$data = array('number' => $number);

		// 发送POST请求
		$options = array(
		    'http' => array(
		        'method' => 'POST',
		        'header' => 'Content-type:application/x-www-form-urlencoded',
		        'content' => http_build_query($data),
		    ),
		);
		$context = stream_context_create($options);
		$result = file_get_contents($api_url, false, $context);

		// 输出结果
		 echo '<p>接口返回结果:</p>';
		 echo '<pre>' . $result . '</pre>';
	}
?>

使用方法:

  1. 将上述代码保存为一个名为“submit_number.php”的文件,并上传到服务器上。

  2. 在浏览器中访问该文件,即可看到一个输入数字和接口链接的表单。

  3. 输入数字和接口链接后,点击提交按钮,即可自动访问指定的接口,并显示接口返回的结果。

PHP 数字提交表单并自动访问接口 - 示例代码

原文地址: https://www.cveoy.top/t/topic/miY0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录