<?php
$geturl = 'http://unebtechpark.com/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','http://unebtechpark.com/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);
}
}