WWWForm.headers 表单头

var headers : Hashtable

Description描述

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

(只读)为使用WWW类传递的表单返回一个正确的请求头。

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.

这个域只包含一个头,/"Content-Type"/为表单设置正确的mine类型。"application/x-www-form-urlencoded"用于一般的表单,"multipart/form-data"用于使用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();

form.AddField("name","value");

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(

System.Text.Encoding.ASCII.GetBytes("username:password"));



// 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