首页 > 解决方案 > 如何使用 PHP 修复 API 不通过 GET 命令返回结果

问题描述

使用 who 是我的代表 API (whoismyrepresentative.com) 并且 get 命令不会呈现来自索引页面上要求邮政编码的输入字段的结果。语法不正确,我需要回显命令吗?

我创建的索引页面:

<section class="form-one">

<form action="search-results.php" method="post">
<label for="zipcode"> Input Zipcode</label>
<input id="zipcode" type="number" name="zip" size="5">
<input type="submit" name="">

</form>
</section>

我调用 GET 命令的 Search-Results.php 页面:

<?php

file_get_contents('https://whoismyrepresentative.com/getall_mems.php?zip=&output=json'.$_GET['zip'].'php?zip=&output=json …');

/*echo $_GET["https://whoismyrepresentative.com/getall_mems.php?zip=&output=json …"];*/

?>

该命令应输出 json。

标签: phpapi

解决方案


这将起作用:

file_get_contents('https://whoismyrepresentative.com/getall_mems.php?zip=' . $_GET['zip'] . '&output=json');

推荐阅读