如何将参数发送到另一个 PHP 网站的 AJAX POST 方法并获取 JSON 信息
How to send parameters to AJAX POST method of another PHP website and fetch JSON information
我正在研究“如何解析来自其他网站的内容”。我正在使用 HTML DOM 解析 来获取信息。我面临的问题是包含 AJAX POST 调用以获取信息的网站。示例网站:Massachussets
1.Here 医生信息是使用 ajax post 方法
获取的
Request URL:http://www.massgeneral.org/assets/javascripts/facets/doctors/doctors.ashx
Request Method:POST
如何将参数传递给此处的 post 方法?。我试过的是
<?php
echo '<center><h3>Massachusetts Information</h3></center>';
// extra headers
//$headers[]= "Accept-Encoding: gzip, deflate";
$fields['center'] = "";
$fields['centerPreSelected'] = false;
//$fields['displayPaging'] = false;
$fields['gender'] = "";
$fields['isEmpty'] = true;
$fields['languages'] = [];
$fields['letter'] = "A";
$fields['letter'] = "";
$fields['locations'] = array();
$fields['numberOfPages'] = 15;
$fields['numberPerPage'] = 50;
$fields['page'] = 1;
$fields['program'] = "";
$fields['range'] = array('Item1' => 0,'Item2' => 49);
$fields['saytLimit'] = "20";
$fields['term'] = "";
$POSTFIELDS = http_build_query($fields);
$headers[] = "Accept: application/json, text/plain, */*";
$headers[] = "Accept-Encoding: gzip, deflate";
$headers[] = "Accept-Language: en-GB,en;q=0.5";
$headers[] = "Connection: keep-alive";
$headers[] = "Content-Type: application/json";
$headers[] = "Host: www.massgeneral.org";
$headers[]="Referer: http://www.massgeneral.org/doctors/";
$login_submit_url = "http://www.massgeneral.org/assets/javascripts/facets/doctors/doctors.ashx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $login_submit_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$result = curl_exec($ch);
echo $result;
没有获取医生信息。
请提供链接或想法来解析它。
您正在使用 http_build_query()
创建 "foo=1&bar=2" 样式格式。该站点需要 json,所以您想使用 json_encode()
。
此外,请省略 gzip header 除非您确定确实要处理 gzip 压缩的响应。
我正在研究“如何解析来自其他网站的内容”。我正在使用 HTML DOM 解析 来获取信息。我面临的问题是包含 AJAX POST 调用以获取信息的网站。示例网站:Massachussets
1.Here 医生信息是使用 ajax post 方法
获取的Request URL:http://www.massgeneral.org/assets/javascripts/facets/doctors/doctors.ashx
Request Method:POST
如何将参数传递给此处的 post 方法?。我试过的是
<?php
echo '<center><h3>Massachusetts Information</h3></center>';
// extra headers
//$headers[]= "Accept-Encoding: gzip, deflate";
$fields['center'] = "";
$fields['centerPreSelected'] = false;
//$fields['displayPaging'] = false;
$fields['gender'] = "";
$fields['isEmpty'] = true;
$fields['languages'] = [];
$fields['letter'] = "A";
$fields['letter'] = "";
$fields['locations'] = array();
$fields['numberOfPages'] = 15;
$fields['numberPerPage'] = 50;
$fields['page'] = 1;
$fields['program'] = "";
$fields['range'] = array('Item1' => 0,'Item2' => 49);
$fields['saytLimit'] = "20";
$fields['term'] = "";
$POSTFIELDS = http_build_query($fields);
$headers[] = "Accept: application/json, text/plain, */*";
$headers[] = "Accept-Encoding: gzip, deflate";
$headers[] = "Accept-Language: en-GB,en;q=0.5";
$headers[] = "Connection: keep-alive";
$headers[] = "Content-Type: application/json";
$headers[] = "Host: www.massgeneral.org";
$headers[]="Referer: http://www.massgeneral.org/doctors/";
$login_submit_url = "http://www.massgeneral.org/assets/javascripts/facets/doctors/doctors.ashx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $login_submit_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$result = curl_exec($ch);
echo $result;
没有获取医生信息。 请提供链接或想法来解析它。
您正在使用 http_build_query()
创建 "foo=1&bar=2" 样式格式。该站点需要 json,所以您想使用 json_encode()
。
此外,请省略 gzip header 除非您确定确实要处理 gzip 压缩的响应。