Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple Custom Headers with www.SetRequestHeader

Discussion in 'Scripting' started by swpowe, Dec 27, 2018.

  1. swpowe

    swpowe

    Joined:
    Mar 20, 2018
    Posts:
    4
    Hello. I'm trying to figure out how to set multiple headers with SetRequestHeader in c#. I'm working with an api that requires an Authorization and Content-Type and I can't seem to get it to work. I've tried Put and Post and I admit I'm a bit out of my depth here. I'd appreciate any help...

    string jsonStringTask = JsonUtility.ToJson(task);


    UnityWebRequest www = UnityWebRequest.Put("url", jsonStringTask);
    www.SetRequestHeader("Authorization", "123245");
    www.SetRequestHeader("Content-Type", "application/json");

    yield return www.SendWebRequest();

    if (www.isNetworkError || www.isHttpError)
    {
    Debug.Log("www.ERROR");

    }
    else
    {
    Debug.Log("Completed");
    }
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    The code should work. What is the exact issue that you get?