<!DOCTYPE html>
<html>
<head>
	<title>在线短网址生成器</title>
</head>
<body>
	<h1>在线短网址生成器</h1>
	<form>
		<label for='long-url'>长网址:</label>
		<input type='text' id='long-url' name='long-url'><br><br>
		<button type='button' onclick='generateShortUrl()'>生成短网址</button><br><br>
		<label for='short-url'>短网址:</label>
		<input type='text' id='short-url' name='short-url'><br><br>
	</form>
	<script>
		function generateShortUrl() {
			var longUrl = document.getElementById('long-url').value;
			var request = new XMLHttpRequest();
			request.open('POST', 'https://api-ssl.bitly.com/v4/shorten', true);
			request.setRequestHeader('Content-Type', 'application/json');
			request.setRequestHeader('Authorization', 'Bearer YOUR_ACCESS_TOKEN');
			request.onreadystatechange = function() {
				if (request.readyState === 4 && request.status === 200) {
					var response = JSON.parse(request.responseText);
					document.getElementById('short-url').value = response.link;
				}
			}
			var data = JSON.stringify({ 'long_url': longUrl });
			request.send(data);
		}
	</script>
</body>
</html>
<p>注:此代码仅为示例,需要在API请求中替换YOUR_ACCESS_TOKEN为自己的访问令牌。</p>
在线短网址生成器 - 免费快速缩短链接

原文地址: https://www.cveoy.top/t/topic/nKjg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录