<?php
// 初始化cURL会话
$ch = curl_init();
// 设置请求URL
curl_setopt($ch, CURLOPT_URL, "https://api.yyx.la/api/post.img.mihoyo");
// 设置POST请求
curl_setopt($ch, CURLOPT_POST, 1);
// 设置请求头
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: YOUR_TOKEN'
));
// 设置POST字段,用户中心获取token,自行替换其他参数
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('param1' => 'value1', 'param2' => 'value2')));
// 返回响应而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行请求并获取响应
$response = curl_exec($ch);
// 关闭cURL会话
curl_close($ch);
// 将响应解析为JSON格式
$data = json_decode($response, true);
// 输出JSON数据
print_r($data);
?>
import requests
# 设置请求URL和头部
url = "https://api.yyx.la/api/post.img.mihoyo"
headers = {
'Authorization': 'YOUR_TOKEN'
}
# 设置POST数据,用户中心获取token,自行替换其他参数
data = {
'param1': 'value1',
'param2': 'value2'
}
# 发送POST请求
response = requests.post(url, headers=headers, data=data)
# 将响应解析为JSON格式
data = response.json()
# 输出JSON数据
print(data)
// 发送POST请求
fetch("https://api.yyx.la/api/post.img.mihoyo", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "YOUR_TOKEN"
},
// 设置POST数据,用户中心获取token,自行替换其他参数
body: new URLSearchParams({
'param1': 'value1',
'param2': 'value2'
})
})
.then(response => response.json()) // 将响应解析为JSON格式
.then(data => console.log(data)) // 输出JSON数据
.catch(error => console.error('Error:', error));
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class Main {
public static void main(String[] args) throws Exception {
// 创建URL对象
URL url = new URL("https://api.yyx.la/api/post.img.mihoyo");
// 打开连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方法
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// 设置请求头
conn.setRequestProperty("Authorization", "YOUR_TOKEN");
// 设置POST数据,用户中心获取token,自行替换其他参数
String data = "param1=" + URLEncoder.encode("value1", "UTF-8") + "¶m2=" + URLEncoder.encode("value2", "UTF-8");
try (OutputStream os = conn.getOutputStream()) {
byte[] input = data.getBytes("utf-8");
os.write(input, 0, input.length);
}
// 读取响应
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
// 输出JSON数据
System.out.println(content.toString());
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main() {
using (HttpClient client = new HttpClient()) {
// 设置请求头
client.DefaultRequestHeaders.Add("Authorization", "YOUR_TOKEN");
// 设置POST数据,用户中心获取token,自行替换其他参数
var values = new Dictionary {
{ "param1", "value1" },
{ "param2", "value2" }
};
var content = new FormUrlEncodedContent(values);
// 发送POST请求
HttpResponseMessage response = await client.PostAsync("https://api.yyx.la/api/post.img.mihoyo", content);
// 将响应解析为字符串
string responseBody = await response.Content.ReadAsStringAsync();
// 输出JSON数据
Console.WriteLine(responseBody);
}
}
}
require 'net/http'
require 'uri'
# 创建URI对象
uri = URI.parse("https://api.yyx.la/api/post.img.mihoyo")
# 创建POST请求
request = Net::HTTP::Post.new(uri)
# 设置请求头
request["Authorization"] = "YOUR_TOKEN"
# 设置POST数据,用户中心获取token,自行替换其他参数
request.set_form_data("param1" => "value1", "param2" => "value2")
# 发送请求并获取响应
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
http.request(request)
end
# 输出JSON数据
puts response.body
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
client := &http.Client{}
// 设置POST数据,用户中心获取token,自行替换其他参数
data := url.Values{}
data.Set("param1", "value1")
data.Set("param2", "value2")
// 创建POST请求
req, err := http.NewRequest("POST", "https://api.yyx.la/api/post.img.mihoyo", bytes.NewBufferString(data.Encode()))
if err != nil {
panic(err)
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "YOUR_TOKEN")
// 发送请求并获取响应
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
// 输出JSON数据
fmt.Println(string(body))
}