响应和发送异步 GET 请求


Responding to and sending asynchronous GET requests

我想创建一个将接收get请求并使用xml响应的应用程序。场景如下:

用户来到site_a.com?site.phpid=abc,从那里我必须向site_b.com/checker.php?id=abc发出GET请求。

如何在用户不离开页面的情况下发出 GET 请求?

在检查器内部.php我必须根据该 id 使用 xml 进行响应

if(isset($_GET['id'])){
  if($_GET['id']=='abc'){
    // respond with xml
 }
}

然后是网站.php我必须收到那个 xml。

谢谢!

最简单的方法,你可以使用file_get_contents:

//site.php?id=abc
$xmlResponse = file_get_contents("site_b.com/checker.php?id=abc");

但要确保allow_url_fopen可能是真的。
http://php.net/manual/en/filesystem.configuration.php

您可以使用

curl .

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://site_b.com/checker.php?id=' . $id); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$xml = curl_exec(); 
curl_close($ch);

卷曲文档