Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

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

Submission failed

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

Close

Cancel

public Dictionary<string,string> headers;

Description

Request headers to use when posting the form.

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 WWWForm.AddBinaryData.

UnityWebRequest.Post copies these headers onto the request it creates, so you only need this property when you build the request yourself.

using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour {

void Start () { WWWForm form = new WWWForm(); form.AddField("name", "value");

// Logs "Content-Type: application/x-www-form-urlencoded". foreach (KeyValuePair<string, string> header in form.headers) Debug.Log(header.Key + ": " + header.Value);

form.AddBinaryData("file", new byte[] { 1, 2, 3 }, "data.bin");

// The form now contains a file, so this logs // "Content-Type: multipart/form-data; boundary=..." instead. foreach (KeyValuePair<string, string> header in form.headers) Debug.Log(header.Key + ": " + header.Value); }

}