Php 为什么我没有得到json响应?

Php 为什么我没有得到json响应?,php,json,forms,smartystreets,Php,Json,Forms,Smartystreets,好的,我认为这应该会生成一个json响应,但是没有打印出来。我错过了什么?我试图通过url请求将此输入发送到,然后获得一个json响应以打印 <?php // Customize this (get ID/token values in your SmartyStreets account) $authId = urlencode("id"); $authToken = urlencode("id"); // Address input $input1 = urlencode($_PO

好的,我认为这应该会生成一个json响应,但是没有打印出来。我错过了什么?我试图通过url请求将此输入发送到,然后获得一个json响应以打印

<?php

// Customize this (get ID/token values in your SmartyStreets account)
$authId = urlencode("id");
$authToken = urlencode("id");

// Address input
$input1 = urlencode($_POST["street"]);
$input2 = urlencode($_POST["city"]);
$input3 = urlencode($_POST["state"]);
$input4 = urlencode($_POST["postcode"]);

// Build the URL
$req = "https://api.smartystreets.com/street-address/?street={$input1}&city={$input2}&state={$input3}&postcode={$input4}&auth-id={$authId}&auth-token={$authToken}";

// GET request and turn into associative array
$result = json_decode(file_get_contents($req));



?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<div id="panel">
     <form action="smarty-geocode.php" name="" method="post">
          <input id="addresses" type="hidden" value="">
          Street Address
          <input id="street" type="textbox" value="" class="address">
          <br />
          City
          <input id="city" type="textbox" value="" class="address">
          <br />
          State
          <input id="state" type="textbox" value="" class="address">
          <br />
          Zipcode
          <input id="postcode" type="textbox" value="" class="address">
          <br />
          Country
          <input id="country" type="textbox" value="" class="address">
          <br />
          <input type="submit" value="submit" id="#mySubmitButton" />
     </form>
</div>
<div id="map-canvas" style="height:40%;top:30px;"></div>
<div>
<?php
echo "<pre>";
print_r($result);
echo "</pre>";
?>
</div>
</body>
</html>

街道地址

城市
状态
Zipcode


没有足够的信息让我调试您URL的输出-但是我认为您应该能够通过将此添加到页面底部来解决此问题:-

     <form action="smarty-geocode.php" name="" method="post">
      <input id="addresses" name="addresses" type="hidden" value="">
      Street Address
      <input id="street" name="street" type="textbox" value="" class="address">
      <br />
      City
      <input id="city" name="city" type="textbox" value="" class="address">
      <br />
      State
      <input id="state" name="state" type="textbox" value="" class="address">
      <br />
      Zipcode
      <input id="postcode" name="postcode" type="textbox" value="" class="address">
      <br />
      Country
      <input id="country" name="country" type="textbox" value="" class="address">
      <br />
      <input type="submit" value="submit" id="#mySubmitButton" />
 </form>

在你提出问题之前,请仔细考虑它是否符合质量标准。我们应该如何帮助你?您不能期望我在
smartystreets.com
上创建帐户。因此,您需要将来自该api请求的响应数据放入问题中。至少提供工作输入值、它们生成的req url以及该url上的响应。您还应该提供$result的var转储。还有一些吹毛求疵,您正在进行的json_解码并没有将其转换为数组;)hek2mgl-这是我的问题。我不知道该怎么做才能得到响应数据。我希望它会生成一个响应,并通过请求变量打印它。然而,这并没有发生。
     <form action="smarty-geocode.php" name="" method="post">
      <input id="addresses" name="addresses" type="hidden" value="">
      Street Address
      <input id="street" name="street" type="textbox" value="" class="address">
      <br />
      City
      <input id="city" name="city" type="textbox" value="" class="address">
      <br />
      State
      <input id="state" name="state" type="textbox" value="" class="address">
      <br />
      Zipcode
      <input id="postcode" name="postcode" type="textbox" value="" class="address">
      <br />
      Country
      <input id="country" name="country" type="textbox" value="" class="address">
      <br />
      <input type="submit" value="submit" id="#mySubmitButton" />
 </form>
$authId = urlencode("id");
$authToken = urlencode("id");