• 创建UnityWebRequests

    创建UnityWebRequests

    WebRequests可以像任何其他对象一样实例化。有两个构造函数可用:

    1. 标准的无参数构造函数创建一个新的UnityWebRequest,其中所有设置为空白或默认。目标网址未设置,未设置自定义标题,并且重定向限制设置为32
    2. 第二个构造函数接受一个字符串参数。它将UnityWebRequest的目标URL分配给字符串参数的值,否则与无参数构造函数相同。

    多个其他属性可用于设置,跟踪状态和检查结果或UnityWebRequest

    1. UnityWebRequest wr = new UnityWebRequest(); // Completely blank
    2. UnityWebRequest wr2 = new UnityWebRequest("http://www.mysite.com"); // Target URL is set
    3. // the following two are required to web requests to work
    4. wr.url = "http://www.mysite.com";
    5. wr.method = UnityWebRequest.kHttpVerbGET; // can be set to any custom method, common constants privided
    6. wr.useHttpContinue = false;
    7. wr.chunkedTransfer = false;
    8. wr.redirectLimit = 0; // disable redirects
    9. wr.timeout = 60; // don't make this small, web requests do take some time

    ?