WWWForm.data 数据

var data : byte[]

Description描述

(Read Only) The raw data to pass as the POST request body when sending the form.

(只读)在发送表单的时,原始数据作为POST请求发送。

Usually, you just pass the WWWForm object directly to the WWW constructor, but you will need this variable if you want to change the request headers sent to the web server.

通常,你只需要直接将WWWForm对象传递给WWW构造函数,但是如果想改变发送到web服务器的头,将需要这个变量。

参见: headers 变量.

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 with our custom headers
// 用自定义的头传递一个请求到URL
var www = new WWW(url, rawData, headers);
yield www;
//.. process results from WWW request here...
// 这里处理WWW请求结果…
Page last updated: 2011-3-19