I’m working on an application for a client which connects to a ruby on rails website.
They currently have a working webform which allows you to supply a name in a text field, and upload a png file from your hard drive.
The data echoed back from a test script is as follows
-----------------------------1551734562961374366152009334
Content-Disposition: form-data; name="name"
HelloWorld
-----------------------------1551734562961374366152009334
Content-Disposition: form-data; name="save_file"
newXML
-----------------------------1551734562961374366152009334
Content-Disposition: form-data; name="thumbnail"; filename="Snapshot.png"
Content-Type: image/png
--BINARY PNG DATA GOES HERE--
-----------------------------1551734562961374366152009334
Content-Disposition: form-data; name="commit"
Save
-----------------------------1551734562961374366152009334--
The output from the following code snippet
WWWForm webPost = new WWWForm();
webPost.AddField( "name", "Test" );
webPost.AddField( "save_file", "newXML" );
webPost.AddField( "commit", "Save" );
webPost.AddBinaryData( "thumbnail", tex.EncodeToPNG() );
Debug.Log( "Sending.... ");
WWW result = new WWW( "TARGET_URL_GOES_HERE", webPost );
yield return result;
if( result.error != null )
{
Debug.Log( "WWW Form Error : " + result.error );
}
else
{
Debug.Log( "Upload Sent : \n" + result.bytes );
}
Yields the following response
--qoDROVw1U7VgaXtuvfBnkeMhIt58Jz4XKMaGZXt3
Content-Type: text/plain; charset="utf-8"
Content-disposition: form-data; name="name"
Test
--qoDROVw1U7VgaXtuvfBnkeMhIt58Jz4XKMaGZXt3
Content-Type: text/plain; charset="utf-8"
Content-disposition: form-data; name="save_file"
newXML
--qoDROVw1U7VgaXtuvfBnkeMhIt58Jz4XKMaGZXt3
Content-Type: text/plain; charset="utf-8"
Content-disposition: form-data; name="commit"
Save
--qoDROVw1U7VgaXtuvfBnkeMhIt58Jz4XKMaGZXt3
Content-Type: image/png
Content-disposition: form-data; name="thumbnail"; filename="thumbnail.png"
--PNG DATA GOES HERE--
--qoDROVw1U7VgaXtuvfBnkeMhIt58Jz4XKMaGZXt3--
When we redirect the POST operations to the actual script, instead of the CGI echo script, their post data is accepted, and the WWWForm’s data is rejected.
My questions are as follows:
- Does it matter that “Content-Type:” precedes “Content-disposition” when Unity sends a request?
- Is it a problem that “Content-Type:” is included for the ‘text/plain’ fields?
I don’t think this is a bug, since unity’s WWWForm output is (as best as I can tell) well formed, and that the bug likely exists within the webapp’s CGI parsing. But I wanted to get some feedback from the Unity devs and/or community at large. Maybe you have encountered problems like this before?
UPDATE:
Just in case it is a malformed request that Unity is generating, here is the response from the server when I execute the above code snippet.
Returned data<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.
Premature end of script headers: ~myuserhome/public_html/appdemo/dispatch.cgi
Additionally, a 500 Internal Server Error
error was encountered while trying to use an ErrorDocument to handle the request.
<HR>
<ADDRESS>Apache/1.3.37 Server at [url]www.mysitehere.com[/url] Port 80</ADDRESS>
</BODY></HTML>

