连接事件

Godot信号

CS
// 信号法
@HttpRequest.Connect(
	HttpRequest.SignalName.RequestCompleted,
	Callable.From<long, long, string[], byte[]>(OnRequestCompleted)
)
// C#事件法
@HttpRequest.RequestCompleted += OnRequestCompleted;
点击展开查看更多

发送请求

CS
Error @HttpRequest.Request(
	string url,
	[string[] customHeaders = null],
	[HttpClient.Method method = HttpClient.Method.Get],
	[string requestData = ""]
)
点击展开查看更多

处理请求

CS
void OnRequestCompleted(long result, long responseCode, string[] headers, byte[] body) {
	if (result != (long)HttpRequest.Result.Success)
		throw new Exception("请求失败");
	if (responseCode != 200)
		throw new Exception("响应码不正确");
	string text = Encoding.UTF8.GetString(body);
	// text...
}
点击展开查看更多

版权声明

作者: Chaim

链接: https://chaim.eu.org/posts/http%E5%AE%A2%E6%88%B7%E7%AB%AF/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键