Home > php教程 > php手册 > PHP用于API接口调试的心得

PHP用于API接口调试的心得

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 11:35:26
Original
1520 people have browsed it

简化了调试的难度,简单说就是将异步请求改变成本地的单线请求。这样就能直接查看到错误提示。
/**
* $name 文件名称可随意命名
* $type 数据的类型:JSON XML null
*/
private function Debug($name,$type=null){

if(empty($_POST)){
//读取数据
$filename ='./Public/'.$name.'.txt'; //文件的保存路径
$handle = fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb'
$contents = fread($handle, filesize($filename));
fclose($handle);
if($type == 'JSON'){
$contents = json_decode($contents);
}
else if($type == 'XML'){
$contents = wddx_deserialize($contents);//把数组序列化为xml字符串
}
$_POST['Datas'] = $contents->Datas;

}else{
//写入数据
$filename ='./Public/';
if(!file_exists($filename)){
mkdir($filename);
}
$filename = $filename.$name.'.txt';
$myfile = fopen($filename, "w") or die("Unable to open file!");
if($type == 'JSON'){
fwrite($myfile, json_encode($_POST));
}
else if($type == 'XML'){
fwrite($myfile, wddx_serialize_value($_POST));
}
else{
fwrite($myfile,$_POST);
}

}

}

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template