Version: 2017.1
public Dictionary<string,string> headers ;

描述

(Read Only) 返回正确的请求标头,以使用 WWW 类发布表单。

此字段只包含一个标头“Content-Type”, 它设置为表单的正确 MIME 类型:“application/x-www-form-urlencoded”(对于普通 表单)和“multipart/form-data”(对于包含使用 AddBinaryData 添加的数据的表单)。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { IEnumerator Start() { WWWForm form = new WWWForm(); form.AddField( "name", "value" ); Hashtable headers = form.headers; byte[] rawData = form.data; string url = "www.myurl.com";

// Add a custom header to the request. // In this case a basic authentication to access a password protected resource. headers["Authorization"] = "Basic " + System.Convert.ToBase64String( System.Text.Encoding.ASCII.GetBytes("username:password"));

// Post a request to an URL with our custom headers WWW www = new WWW(url, rawData, headers); yield return www; //.. process results from WWW request here... } }