如何将POST请求发送到XML以获取数据?

时间:2012-10-26 08:28:11

标签: php xml http-post

  

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

有一个XML可以通过POST省省号来返回城市列表。 (它通过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

1 个答案:

答案 0 :(得分:3)

使用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);
相关问题