- Home /
The question is answered, right answer was accepted
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".
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 >
anyhow, 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.
Answer by elenzil · Mar 30, 2016 at 05:25 PM
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;
funny; a year and a month later, i ran into this problem again, and completely re-diagnosed it again w/ WireShark, then googled for something appropriate and found this... memory like a sieve.
Thanks for being the internet hero we do not deserve and answering your own question. Exactly my problem, solution worked like a charm. https://xkcd.com/979/
Runs into problem. Googles solution. Finds own solution.
Thank you so much for this. I've spent hours trying to figure out why I was getting errors when posting JSON data to a .NET Web API service. Your solution solved it for me.
Such an easy work around! Thanks, this was driving me crazy, the server side of things for me is a node.js express stack and bodyPraser.json() doesn't work with url encoded jsons...
Dear Barbara, another year has passed and unsuspecting Unity users are still being baffled by 415 Unsupported $$anonymous$$edia 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.
Thank you so much man. I have spend all f*cking day to solve this problem, and at the end I found your answer.
Follow this Question
Related Questions
Upload large files 0 Answers
HTTP Response Headers? 3 Answers
Reliable way to download textures 1 Answer
Need Help in Networking i.e WWW 1 Answer