# Python示例
import requests
url = "https://api.toolbc.com/v1/ai/ask"
headers = {
"Content-Type": "application/json"
}
data = {
"api_key": "test_1234567890abcdef",
"question": "什么是人工智能?",
"model": "general"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
// Go示例
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://api.toolbc.com/v1/ai/ask"
data := map[string]interface{}{
"api_key": "your_api_key",
"question": "什么是人工智能?",
"model": "general",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
// Java示例
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("https://api.toolbc.com/v1/ai/ask");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
String jsonInputString = "{\"api_key\": \"test_1234567890abcdef\", \"question\": \"什么是人工智能?\", \"model\": \"general\"}";
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
}
// PHP示例
$url = "https://api.toolbc.com/v1/ai/ask";
$data = array(
"api_key" => "test_1234567890abcdef",
"question" => "什么是人工智能?",
"model" => "general"
);
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;