Since **Unity2017.2** we've been using a custom build pipeline that can be triggered by sending a JSON webrequest to the pipeline's API (using editor coroutines). I had specifically implemented this request using the **UnityWebRequest** class due to WWW being deprecated in the future. The implementation of this webrequest has worked all the way up to **Unity2018.2.21f1** without issue (see code snippet below).
However, for some reason the exact same implementation returns a **response code 403 (forbidden)** in **Unity 2018.3.4f1**. I've been looking through patch notes and documentation for web requests in 2018.3, but I can't seem to find any significant changes, other than the WWW class being deprecated.
If there's anyone out there who can point me in the right direction, I'd be eternally grateful.
public static UnityWebRequest CreatePostRequest(string url, string jsonBody, string username, string password)
{
var request = new UnityWebRequest(url, "POST");
request.method = "POST";
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("Accept", "application/json");
request.SetRequestHeader("Authorization", BasicAuthorizationHeader(username, password));
return request;
}
public static string BasicAuthorizationHeader(string username, string password)
{
string auth = username + ":" + password;
string final = "Basic " + EncodeStringAsBase64(auth);
return final;
}
public static string EncodeStringAsBase64(string input)
{
byte[] bytesToEncode = Encoding.UTF8.GetBytes(input);
string encodedText = Convert.ToBase64String(bytesToEncode);
return encodedText;
}
↧