C# 实现图灵机器人 V2 版 API 调用

C# 图灵机器人 V2 版 API 调用示例

本代码演示如何使用 C# 调用图灵机器人 V2 版 API。 请确保您已注册图灵账号,创建了机器人并获取了 APIKEY。

// 请替换为您的 API Key
string apiKey = "YOUR_API_KEY";

// 请替换为您的用户 ID
string userId = "YOUR_USER_ID";

// 构造请求 URL
string url = $"https://api.turingos.cn/v2/api.php?key={apiKey}&userid={userId}";

// 构造请求数据
string postData = "info=你好";

// 创建 WebClient 对象
using (var client = new WebClient())
{
    // 设置请求头
    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

    // 发送 POST 请求并获取响应
    string response = client.UploadString(url, postData);

    // 处理响应结果
    Console.WriteLine(response);
}

注意:

  • 请将代码中的 YOUR_API_KEYYOUR_USER_ID 替换为您的实际值。
  • 您可以根据需要修改 postData 中的 info 参数值,以发送不同的消息给机器人。
zip
TulingDemo.zip 预估大小:63个文件
folder
TulingDemo 文件夹
folder
.vs 文件夹
folder
config 文件夹
file
applicationhost.config 81KB
folder
TulingDemo 文件夹
folder
v15 文件夹
file
.suo 58KB
folder
Server 文件夹
folder
sqlite3 文件夹
file
storage.ide 588KB
file
storage.ide-shm 32KB
folder
db.lock 文件夹
file
storage.ide-wal 3.93MB
file
请求示例.json 441B
file
输出示例.json 645B
file
异常返回说明.txt 391B
folder
TulingDemo 文件夹
folder
bin 文件夹
folder
Release 文件夹
folder
Debug 文件夹
file
TulingDemo.exe 12KB
file
TulingDemo.pdb 30KB
file
Newtonsoft.Json.dll 647KB
file
TulingDemo.exe.config 186B
file
Newtonsoft.Json.xml 669KB
file
Form1.Designer.cs 7KB
file
packages.config 144B
file
Program.cs 522B
folder
obj 文件夹
folder
Debug 文件夹
file
TulingDemo.exe 12KB
file
TulingDemo.pdb 30KB
folder
TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs 文件夹
file
TulingDemo.csproj.FileListAbsolute.txt 2KB
file
TulingDemo.csprojAssemblyReference.cache 147KB
file
DesignTimeResolveAssemblyReferencesInput.cache 7KB
folder
TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs 文件夹
file
TulingDemo.csproj.GenerateResource.cache 1012B
file
DesignTimeResolveAssemblyReferences.cache 1KB
folder
TempPE 文件夹
file
Properties.Resources.Designer.cs.dll 4KB
file
TulingDemo.Properties.Resources.resources 180B
file
TulingDemo.csproj.CoreCompileInputs.cache 42B
folder
TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs 文件夹
file
TulingDemo.Form1.resources 180B
folder
TulingDemo.csproj.CopyComplete 文件夹
file
Form1.cs 3KB
file
Form1.resx 6KB
file
App.config 186B
folder
Properties 文件夹
file
Resources.resx 5KB
file
Settings.settings 249B
file
AssemblyInfo.cs 1KB
file
Settings.Designer.cs 1KB
file
Resources.Designer.cs 3KB
file
TulingDemo.csproj 4KB
folder
packages 文件夹
folder
Newtonsoft.Json.11.0.2 文件夹
file
.signature.p7s 9KB
file
Newtonsoft.Json.11.0.2.nupkg 2.3MB
file
LICENSE.md 1KB
folder
lib 文件夹
folder
netstandard1.3 文件夹
file
Newtonsoft.Json.dll 636KB
file
Newtonsoft.Json.xml 656KB
folder
net35 文件夹
file
Newtonsoft.Json.dll 464KB
file
Newtonsoft.Json.xml 514KB
folder
net20 文件夹
file
Newtonsoft.Json.dll 501KB
file
Newtonsoft.Json.xml 569KB
folder
netstandard2.0 文件夹
file
Newtonsoft.Json.dll 641KB
file
Newtonsoft.Json.xml 667KB
folder
portable-net45+win8+wp8+wpa81 文件夹
file
Newtonsoft.Json.dll 617KB
file
Newtonsoft.Json.xml 649KB
folder
net45 文件夹
file
Newtonsoft.Json.dll 647KB
file
Newtonsoft.Json.xml 669KB
folder
netstandard1.0 文件夹
file
Newtonsoft.Json.dll 618KB
file
Newtonsoft.Json.xml 649KB
folder
portable-net40+sl5+win8+wp8+wpa81 文件夹
file
Newtonsoft.Json.dll 431KB
file
Newtonsoft.Json.xml 488KB
folder
net40 文件夹
file
Newtonsoft.Json.dll 528KB
file
Newtonsoft.Json.xml 526KB
file
TulingDemo.sln 1KB
...
zip 文件大小:5.41MB