【问题标题】:How to send POST Request to XML to get data? [duplicate]如何向 XML 发送 POST 请求以获取数据? [复制]
【发布时间】:2012-10-26 08:28:11
【问题描述】:

可能重复:
POST XML to URL with PHP and Handle Response

有一个 XML 可以通过 POSTing 省份 ID 返回城市列表。 (它通过 POST 接受 id) http://example.com/get_city_list.xml

<cities>
  <city>
    <id></id>
    <name></name>
  </city>

  <city>
    <id></id>
    <name></name>
  </city>

  <city>
    <id></id>
    <name></name>
  </city>
<cities>

如何将省 ID(通过 POST REQUEST)发送到 XML?

我正在使用 php 5

【问题讨论】:

    标签: php xml http-post


    【解决方案1】:

    使用 CURL:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    
    $data = array(
        'foo' => 'foo foo foo',
        'bar' => 'bar bar bar',
        'baz' => 'baz baz baz'
    );
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2016-05-30
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多