1

我试图从远程服务器检索数据,但它不工作并发送空数据。这是我尝试过的代码:

define('WWW_PATH', dirname(__FILE__) . '/../..');

set_include_path(implode(PATH_SEPARATOR, array(realpath(WWW_PATH . '/library'), get_include_path())));

require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();

$autoloader->registerNamespace('Zend_');
$data = array(
    'sr' => '3',
    'et' => '3',
    'exam' => 'ssc',
    'year' => '2007',
    'board' => 'dhaka',
    'roll' => '494548'
);
$client = new Zend_Http_Client();
$client->setUri('http://www.educationboardresults.gov.bd/regular/result.php');
$client->setParameterPost($data);
$response = $client->request('POST');
$result = array('data'=>$response->getBody());
echo json_encode($result);

当我尝试回显结果时,它会重定向到 index.php 页面。任何关于如何获取数据的建议。我试过 curl 但这里也有同样的问题:(

$post_data['sr'] = '3';
$post_data['et'] = '3';
$post_data['exam'] = 'ssc';
$post_data['year'] = '2007';
$post_data['board'] = 'dhaka';
$post_data['roll'] = '494548';


foreach ( $post_data as $key => $value) 
{
    $post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);


$curl_connection = curl_init('http://www.educationboardresults.gov.bd/regular/result.php');

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POST, 1);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

$result = curl_exec($curl_connection);
curl_close($curl_connection);
//var_dump($result);
$data= array('data'=>$result);
echo json_encode($data);

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://www.educationboardresults.gov.bd/regular/result.php",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'sr' => '3',
        'et' => '3',
        'exam' => 'ssc',
        'year' => '2007',
        'board' => 'dhaka',
        'roll' => '494548',
    ),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
$data= array('data'=>$result);
echo json_encode($data);
4

1 回答 1

0

我认为这是因为http://www.educationboardresults.gov.bd. 当我尝试在浏览器中访问 url 时,它正在重定向到www.educationboardresults.gov.bd/regular/index.php. 您必须使用$client->setAuth();方法登录到该站点,然后获取响应正文。我没有亲自使用它,但是Zend_Http_Client - Advanced Usage会给出一个更好的想法。

于 2013-11-11T04:02:25.203 回答