prevent UnityWebRequest.Post() from Url-Encoding the data ?

per the docs for UnityWebRequest.Post(), the post body “Will be URLEncoded via WWWTranscoder.URLEncode prior to transmission”.

< rant >
this is crazy. nowhere does the HTTP spec require that POST data be URL-Encoded.
a good HTTP client should assume the user (me) knows what they’re doing and can URL-Encode their own data if required. look at Curl. does Curl automatically url-encode the body if the method is POST ? no. if you’re writing an HTTP client and you find yourself diverging from what Curl does, check yourself.
< /rant >

is there a way to disable this ?
i’ve tried:

  • setting the content type “text/plain”
  • setting the UploadHandler’s content type to “text/plain”

neither works.

a workaround that does seem to work but is a total hack is to use UnityWebRequest.Put() instead, and change the method to POST before Sending it.

also, this is a change from the previous WWW HTTP Client framework, and the statement in the manual that “For end-users who only employ common WWW use cases, transitioning to the new system should be almost a find-and-replace process.” is way off-base because of this.

better workaround than the WebRequest.Put() hack is to build a WebRequest ‘from scratch’:

  request                 = new UnityWebRequest(url);
  request.uploadHandler   = new UploadHandlerRaw(myStringToByteArrayConverter(body));
  request.downloadHandler = new DownloadHandlerBuffer();
  request.method          = UnityWebRequest.kHttpVerbPOST;

Dear Barbara, another year has passed and unsuspecting Unity users are still being baffled by 415 Unsupported Media Type responses. It makes no sense to me why, in the json world we live in, when you already have multiple overloads for form data, that a string argument overload would assume application/x-www-form-urlencoded.