`/api/urlturn` 接口用于将长 URL 转换为短 URL 并存储到数据库中。
{
"keyword": "短 URL 的唯一标识符",
"shortened_url": "生成的短 URL"
}{
"error": "Invalid URL"
}{
"error": "Invalid token"
}# 导入必要的库 import requests # 定义 URL 和长 URL 及 Token url = "https://imagehub.alicoredata.group/api/urlturn" long_url = "http://example.com/some-long-url" token = "your_token_here" # 发送 POST 请求并打印响应数据 response = requests.post(url, data={'url': long_url, 'token': token}) print(response.json())
// 导入必要的类库 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws Exception { // 定义 URL 和参数映射表 String url = "https://imagehub.alicoredata.group/api/urlturn"; Map<String, String> params = new HashMap<>(); params.put("url", "http://example.com/some-long-url"); params.put("token", "your_token_here"); StringBuilder postDataBuilder = new StringBuilder(); for (Map.Entry<String, String> param : params.entrySet()) { if (postDataBuilder.length() != 0) postDataBuilder.append('&'); postDataBuilder.append(param.getKey()).append('=').append(param.getValue()); } String postData = postDataBuilder.toString(); // 执行 curl 命令并读取输出 Process process = Runtime.getRuntime().exec(new String[]{"curl", "-X", "POST", "--data", postData, url}); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) System.out.println(line); reader.close(); } }
// 导入 axios 库 const axios = require('axios'); // 定义 URL 和长 URL 及 Token const url = 'https://imagehub.alicoredata.group/api/urlturn'; const longUrl = 'http://example.com/some-long-url'; const token = 'your_token_here'; // 发送 POST 请求并处理响应数据 axios.post(url, { 'url': longUrl, 'token': token }) .then(response => console.log(response.data)) .catch(error => console.error(error));