言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

WWWForm.headers

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public var headers: Dictionary<string,string>;
public Dictionary<string,string> headers;
public headers as Dictionary<string,string>

Description

WWWクラスを使用してフォームをPOSTするための正しいリクエストヘッダーを返します (Read Only)

このフィールドは /"Content-Type"/ のみを含んでおり、 通常のフォームではmimeTypeは "application/x-www-form-urlencoded" 、 AddBinaryData を使用して追加したデータがあるフォームは "multipart/form-data" に設定されます。

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
var www = new WWW(url, rawData, headers);
yield www;
//.. process results from WWW request here...
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public WWWForm form = new WWWForm();
    public stringstring headers = form.headers;
    public byte[] rawData = form.data;
    public string url = "www.myurl.com";
    public WWW www = new WWW(url, rawData, headers);
    IEnumerator Example() {
        form.AddField("name", "value");
        headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes("username:password"));
        yield return www;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public form as WWWForm = WWWForm()

	public headers as System.Collections.Generic.Dictionary[of string, string] = form.headers

	public rawData as (byte) = form.data

	public url as string = 'www.myurl.com'

	public www as WWW = WWW(url, rawData, headers)

	def Example() as IEnumerator:
		form.AddField('name', 'value')
		headers['Authorization'] = ('Basic ' + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes('username:password')))
		yield www