php中转,我需要PHP做个中转,post上传数据到网站,然后返回结果,PHP代码如下,哪块错了啊?...

问题补充:

header('Content-Type: text/html; charset=utf-8');

// header('Content-Type: application/json; charset=utf-8');

header('Access-Control-Allow-Origin: *');

header("Access-Control-Allow-Credentials: true");

header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');

header('Cache-Control: no-cache');

header('Pragma: no-cache');

header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token, X-Requested-With, Authorization');

$start = time() + microtime();

$req_params = array_merge($_GET, $_POST);

if(!array_key_exists('dn', $req_params)) {

die(json_encode(array(

'error' => true,

'result' => '缺少 dn'

)));

}

$enc = (isset($req_params['enc']) && !empty($req_params['enc'])) ? $req_params['enc'] : 'E';

$method = (isset($req_params['method']) && !empty($req_params['method'])) ? $req_params['method'] : 'queryDomainInfo';

$client = (isset($req_params['client']) && !empty($req_params['client'])) ? $req_params['client'] : 'agent15422';

$queryType = (isset($req_params['queryType']) && !empty($req_params['queryType']) ? $req_params['queryType'] : 'admType';

$password = (isset($req_params['password']) && !empty($req_params['password']) ? $req_params['password'] :'24265528';

$url = 'http://api.xinnet.com/domain/api.gb';

$data = array(

'enc' => $enc,

'method' => $method,

'queryType' => $queryType,

'client' => $client,

'charset' => 'utf-8',

'dn' => $req_params['dn'],

'checksum' => MD5('queryDomainInfo'.$client.$password.$dn.$queryType),

);

// use key 'http' even if you send the request to https://...

$options = array(

'http' => array(

'header' => "Content-type: application/x-www-form-urlencoded\r\n",

'method' => 'POST',

'content' => http_build_query($data)

)

);

$error = false;

$context = stream_context_create($options);

$result = file_get_contents($url, false, $context);

if ($result === FALSE) {

/*Handle error*/

// echo "error
\n";

$error = true;

}

// echo($result) . "
\n";

$end = time() + microtime();

// echo ($end - $start);

echo json_encode(array(

'error' => $error,

'result' => $result,

'time' => $end - $start

));

?>补充:哪位高人指点我一下啊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值