WWWForm.headers 表单头

var headers : Hashtable


(Read Only) Returns the correct request headers for posting the form using the WWW class.


This field only contains one header, /"Content-Type"/, which is set to the correct mime type for the form: "application/x-www-form-urlencoded" for normal forms and "multipart/form-data" for forms containing data added using AddBinaryData.


using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public WWWForm form = new WWWForm();
	public System.Collections.Hashtable headers = form.headers;
	public byte[] rawData = form.data;
	public string url = "www.myurl.com";
	public WWW www = new WWW(url, rawData, headers);
	public IEnumerator Awake() {
		form.AddField("name", "value");
		headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes("username:password"));
		yield return www;
var form = new WWWForm();
var headers = form.headers;
var rawData = form.data;
var 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(

// Post a request to an URL
// 传递一个请求到URL
var www = new WWW(url, rawData, headers);
yield www;
//.. process results from WWW request here...
// 这里处理WWW请求结果…
Page last updated: 2011-3-19