随机一言
随机获取一言

接口地址: https://api.zdck8.com/Api/php/suijiyiyan

返回格式: JSON

请求方式: GET

请求示例: https://api.zdck8.com/Api/php/suijiyiyan?

请求参数说明:

名称 必填 说明

返回参数说明:

名称 类型 说明

返回示例:

{"data":{"hitokoto":"u4e0du8336u4e0du996duff0cu4e0du8a00u4e0du8beduff0cu4e00u5473u4f9bu4ed6u6194u60b4u3002","from":"u9e4au6865u4ed9u00b7u8bf4u76dfu8bf4u8a93"}}

错误码格式说明:

名称 类型 说明

PHP代码示例:


$get="https://api.zdck8.com/Api/php/suijiyiyan?";
$result=file_get_contents($get);
if($result)
{
//请求成功
echo $result;
}else{
//请求失败
}

$url='https://api.zdck8.com/Api/php/suijiyiyan';
$data=array(
);
$data=http_build_query($data);
$option =array('http'=>array('method'=>'POST','content'=>$data));
$context=stream_context_create($option);
$result=file_get_contents($url,false,$context);
if($result)
{
  //成功
  echo $result;
}else{
  //失败
}

Java代码示例:


String httpurl = "https://api.zdck8.com/Api/php/suijiyiyan?";
HttpURLConnection connection = null;
InputStream is = null;
BufferedReader br = null;
String result = null;
try {
URL url = new URL(httpurl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
connection.connect();
if (connection.getResponseCode() == 200) {
is = connection.getInputStream();
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuffer sbf = new StringBuffer();
String temp = null;
while ((temp = br.readLine()) != null) {
sbf.append(temp);
}
result = sbf.toString();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != br) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != is) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
connection.disconnect();
}
System.out.println(result);//返回内容

PrintWriter out = null;
BufferedReader in = null;
String result = "";
String param ="";
String url ="https://api.zdck8.com/Api/php/suijiyiyan?";
try {
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!"+e);
e.printStackTrace();
}
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
System.out.println(result);//返回内容

JavaScript代码示例:


var url = "https://api.zdck8.com/Api/php/suijiyiyan?"
var xhrGet = new XMLHttpRequest();
xhrGet.open('GET',url, true);
xhrGet.send();
xhrGet.onreadystatechange = function() {
if (xhrGet.readyState == 4 && xhrGet.status == 200) {
//成功
var result = xhrGet.responseText;
console.log(result);
} else {
//失败
}
}

var url ="https://api.zdck8.com/Api/php/suijiyiyan";
var data = "";
var xhrPost = new XMLHttpRequest();
xhrPost.open('POST', url, true);
xhrPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhrPost.send(data);
xhrPost.onreadystatechange = function() {
if (xhrPost.readyState == 4 && xhrPost.status == 200) {
//成功
var result = xhrPost.responseText;
console.log(result);
} else {
//失败
}
}