<?php
$geturl = 'https://c24.cn/api/create';
$param = http_build_query([
'token' => '你的Token'
,'longurl' => '你的长网址'
,'format' => 'text'
]);
$opts = [
'http' => array(
'method' => "POST",
'header' => "Content-type: application/x-www-form-urlencoded\r\n".
"Content-length:".strlen($param)."\r\n" .
"Cookie: foo=bar\r\n" .
"\r\n",
'content' => $param,
),
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
)
];
$dwz = file_get_contents($geturl, $param, stream_context_create($opts));
echo $dwz;
?>
var ajax = new XMLHttpRequest();
var token = 'd3be719c083dd26e0799ef70461baf36';
var longUrl = 'http://test.com/page/doc.html';
ajax.open('post','https://c24.cn/api/create', 'true');
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
// 发送请求
var Post = 'token='+token+'&longurl='+encodeURIComponent(longUrl)+'&format=text';
ajax.send(Post);
ajax.onreadystatechange = function () {
if (ajax.readyState === 4 && ajax.status === 200) {
//获取缩短后的网址
console.log(ajax.responseText);
}
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import urllib.parse
import json
url = 'https://c24.cn/api/create'
method = 'POST'
content_type = 'application/x-www-form-urlencoded'
# TODO: 设置Token
token = 'd3be719c083dd26e0799ef70461baf36'
# TODO:设置待创建的长网址
longurl = urllib.parse.quote("https://baidu.com")
Post = 'token='+token+'&longurl='+longurl+'&format=text'
# 发起请求
response = requests.post(url=url, data=Post, {'Content-Type':content_type})
# 读取响应
print(response.text)