Php 将用户输入传递到web服务

Php 将用户输入传递到web服务,php,json,Php,Json,Hi需要向web服务传递一些值。下面的代码运行良好。我唯一的问题是,在本例中,值“3620”(邮政编码)和“600”(用法)应该由用户在页面上输入,然后传递给返回结果的Web服务($json)。最好的方法是什么?html表单?我更希望用户在点击“Go”按钮时填写两个字段,但结果显示在同一页上。有人知道如何使用户输入这两个值吗 <?php $service_url = 'http://test'; $curl = curl_init($serv

Hi需要向web服务传递一些值。下面的代码运行良好。我唯一的问题是,在本例中,值“3620”(邮政编码)和“600”(用法)应该由用户在页面上输入,然后传递给返回结果的Web服务($json)。最好的方法是什么?html表单?我更希望用户在点击“Go”按钮时填写两个字段,但结果显示在同一页上。有人知道如何使用户输入这两个值吗

          <?php 

      $service_url = 'http://test';
      $curl = curl_init($service_url);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                                                  'Content-Type: application/json',
                                                  'Connection: Keep-Alive'
                                                  ));
      curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($curl, CURLOPT_USERPWD, "test:test");
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
           $curl_post_data = array(
                "postalcode" => 3620,
                "usage" => 600,
                );
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
      $curl_response = curl_exec($curl);
      $json = json_decode($curl_response);
      curl_close($curl);

      var_dump($json);

    ?>


和$\u POST或$\u GET。jquery和其他工具都有很好的EasyAjax支持或evt。使用新的html5跨域ajax直接向服务发送ajax帖子。您不认为向web服务发送
$curl\u post\u data
与向特定web服务提交包含名为“postalcode”和“usage”字段的html表单是一样的吗?是的,您需要表单来完成这项工作。您可以将任何php变量传递给CURL。在客户端上,并在代码中输入$\u POST或$\u GET。jquery和其他工具都有很好的EasyAjax支持或evt。使用新的html5跨域ajax直接向服务发送ajax帖子。您不认为向web服务发送
$curl\u post\u data
与向特定web服务提交包含名为“postalcode”和“usage”字段的html表单是一样的吗?是的,您需要表单来完成这项工作。您可以将任何php变量传递给CURL。