- Home /
Question by
siddharth3322 · Jun 18, 2016 at 09:22 AM ·
wwwwebrequestwwwformpostwebservice
Pass Header Data in UnityWebRequest
I want to pass header information to my web service call. I have following code to use but don't know how to pass header data with same request.
void Start ()
{
StartCoroutine (LoadLoginInfo ());
}
IEnumerator LoadLoginInfo ()
{
Debug.Log("Load Login Info");
WWWForm form = new WWWForm ();
form.AddField ("username", "admin");
form.AddField ("password", "Admin123#");
UnityWebRequest www = UnityWebRequest.Post (url, form);
yield return www.Send();
if (www.isError) {
Debug.Log (www.error);
} else {
Debug.Log ("Data: " + www.downloadHandler.text);
}
}
Please give me some help in this.
Comment
Best Answer
Answer by siddharth3322 · Nov 07, 2021 at 04:14 PM
I have tested this and solved this problem with the following solution:
webRequest.SetRequestHeader("username", "admin");
webRequest.SetRequestHeader("password", "Admin123#");
Answer by Sandip_Artoon · May 08, 2017 at 08:34 PM
you may try like this.
WWWForm postForm = new WWWForm ();
postForm.headers ["enctype"] = "multipart/form-data";