Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

UnityWebRequest ContentType not Overriding

$
0
0
I am constructing a file post to a REST api. The REST api is specifically looking for mulipart/form-data content. Seems like now matter how I try and override it, the content-type when it gets to the server is always "application/x-www-form-urlencoded". Does anyone know how to send content as "multipart/form-data"? byte[] data = File.ReadAllBytes (@""); List postForm = new List (); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add (new MultipartFormDataSection ("SectionHeader", "data", "text/plain")); postForm.Add(new MultipartFormFileSection("SectionHeader", data, "data", "application/octet-stream")); string boundaryString = "---NextPart_" + Guid.NewGuid ().ToString () + "---"; byte[] boundary = Encoding.ASCII.GetBytes (boundaryString); UnityWebRequest www = UnityWebRequest.Post(baseApiUrl + dataApiUrl, postForm, boundary); www.uploadHandler.contentType = "multipart/form-data"; www.SetRequestHeader ("Authorization", completeToken.token_type + " " + completeToken.access_token); yield return www.Send(); if(www.isError) { Debug.LogError(www.error); } else if (www.responseCode != 200) { //This is where I am getting 415 Unsupported Media Type } else{ Debug.Log("Form upload complete!"); }

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>