文档

Unity Engine

Unity Engine

Unity Web Request Creating Unity Web Requests

Create and configure a UnityWebRequest using its available constructors.
阅读时间1 分钟最后更新于 1 个月前

与任何其他对象一样,WebRequest 也可以实例化。可使用两个构造函数:
  • 标准的无参数构造函数将创建一个所有设置均为空或默认值的新 UnityWebRequest。此函数中不会设置目标 URL,不会设置自定义标头,并且重定向限制设置为 32。
  • 第二个构造函数采用一个字符串参数。此构造函数将 UnityWebRequest 的目标 URL 分配给字符串参数的值,除此之外,与无参数的构造函数相同。
还可以设置多个其他属性,用于跟踪状态,以及检查 UnityWebRequest 的结果。

示例

UnityWebRequest wr = new UnityWebRequest(); // Completely blankUnityWebRequest wr2 = new UnityWebRequest("https://www.mysite.com"); // Target URL is set// the following two are required to web requests to workwr.url = "https://www.mysite.com";wr.method = UnityWebRequest.kHttpVerbGET; // can be set to any custom method, common constants providedwr.useHttpContinue = false;wr.chunkedTransfer = false;wr.redirectLimit = 0; // disable redirectswr.timeout = 60; // don't make this small, web requests do take some time