I want to use UnityWebRequest to send a Form Data parameter “ssl” including an ssl string (see picture below).
I already tried the two methods below. But it did not work.
Sending a simple payload did reach the server however.
Does formData change the header of UnityWebRequest? Or am I overlooking something else?
IEnumerator Method(string url, string ssl){
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
formData.Add(new MultipartFormDataSection("ssl=" + ssl);
UnityWebRequest www;
www = UnityWebRequest.Post(url, formData);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
userData = www.downloadHandler.text;
}
}
and
IEnumerator Method(string url, string ssl){
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
formData.Add(new MultipartFormDataSection("ssl=" +
ssl.Replace("+","%2B").Replace("=","%3D").Replace("/","%2F")));
UnityWebRequest www;
www = UnityWebRequest.Post(url, formData);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
userData = www.downloadHandler.text;
}
}
You are sending a raw section of multipart form.
I bevieve what you want is a simple form with ssl filed in it?
In such case you should use WWWForm.
If you do indeed want a multipart form, then you probably should use MultipartFormDataSection contructor with name argument besides payload, rather than concatenating “ssl=” manually.
Thank you. That’s a good tip.
Now I am using WWWForm like this:
IEnumerator Method(string url, string ssl){
WWWForm form = new WWWForm();
form.AddField("ssl", ssl);
UnityWebRequest www;
www = UnityWebRequest.Post(url, form);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
userData = www.downloadHandler.text;
}
}
But I am still not able to login (changed to random data in the picture) and recieve a bad Request.
Could it be connected to “proto”? I have no clue what that is.
I have no clue what you are trying to achieve. I can only tell, how to transfer the data from client to server.
If you know have an example request that succeeds, I can help to replicate that in Unity.
But beyond that you are on your own. I have zero idea about that (server side?) code you are showing, nor I have any clue what the value of that ssl field is nor where you got it from, nor whether it is valid etc…
I really apriciate your that you are trying to help me. 
An actual successful request I am trying to replicate is this:
Does this help? Otherwise, thank you for your effort. 
The hex numbers inside the url are generated as well as the ssl. I already successfuly replicated that.
So the last step I have to take is to send the generated ssl to the generated url.
Have you tried using http debugging proxy like Fiddler or Charles to intercept and view the raw request? When you have the successful request, that’s what you should do and compare.
One item that catches my eye is the query in url. Maybe not related, but somewhat strange for a POST request.
1 Like
Using Fiddler is a good tip. I never used it befor. But I still don’t know what I am exactly looking for. The two raw requests seem pretty different to me:
Unity:
POST https://item.engineering/dqart/91bf16b6f0e8573e4eddf1a265b781e9403:5e62d6a669ba526d772f3c63ff7764da/u/l/?version=alpha4 HTTP/1.1
Host: item.engineering
User-Agent: UnityPlayer/2019.2.3f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)
Accept: */*
Accept-Encoding: identity
Content-Type: application/x-www-form-urlencoded
X-Unity-Version: 2019.2.3f1
Content-Length: 382
ssl=OH%2bbbJrfJ6U1b0mYn9Z5MZTH4SIpIS%2btt9xpcZWzN7o8fcHK5GFCbFVogPaBzKwPkDdwgkSYE90BzjTVhR0O%2byy7uAZt3dlsKJ%2bTRKO8KP%2f2ICwEFUMe1kgmkErSP4BvLm8filqt%2bmSLwX51wz0r3rFj1lmJKNOp3168CcFx6yj7zrjmNDwubqyN28S2v%2bmVmGCIyu671%2b84QcYfkjJMQR1J%2b7ySiDFrAJLce3Z3UhQpYqESdPqDayB64R6%2fou58b20CPXEUyE4WI8mWKc%2bynj8g0VJV8a%2bVxkwIYQW6rrDdj59Q0z14Vn43TqtnhyWcIwd%2ffpkJjJPekC%2fiH%2fgZPQ%3d%3d
Web browser:
POST https://item.engineering/dqart/76385dd43bb2c8c74e3a37fd1b1f529d:0328c5e798876a06df5d6b869550241c/u/l/?version=alpha4 HTTP/1.1
Host: item.engineering
Connection: keep-alive
Content-Length: 364
Accept: */*
Origin: https://item.engineering
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Sec-Fetch-Mode: cors
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Sec-Fetch-Site: same-origin
Referer: https://item.engineering/DEde/tools/engineeringtool/
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: _gcl_au=1.1.794253783.1567584723; _ga=GA1.2.1886642906.1567584716; _gac_UA-66605572-1=1.1567584731.Cj0KCQjwwb3rBRDrARIsALR3XeY9xQbwOWUUkVVRgcXa4EMIhL4US6HqI-NNqdmtPoeBylTBNbxO2Z8aAgF_EALw_wcB; _gac_UA-66605572-2=1.1567584716.Cj0KCQjwwb3rBRDrARIsALR3XeY9xQbwOWUUkVVRgcXa4EMIhL4US6HqI-NNqdmtPoeBylTBNbxO2Z8aAgF_EALw_wcB; _gid=GA1.2.1187402807.1571035634; _gat_UA-66605572-2=1; _gat_UA-66605572-39=1; _gat_UA-66605572-1=1
ssl=DGbjiQ2RgWGhYRUWkfMNloXmg9doSXD6dyT4HAdwUTnNMSzGmsduWlkq%2Fldjts%2BR9hFxSf9nKF1PxhLcCVA289%2BX2VOd3CBRLu%2FCud2TYDVNFxRT9TcFa4ngfofpDehXMk4zoQucDjlkPhNEb1W3yDxkROn1AZV1OyqoNi1vIrWzPYORtRgTkGzojxbt1OyeKA06LVYfNjW2yok0fZvE339EudfHmzN01jkhCzugHnBKl2sfZwtRgK0LQD3WiHz2egvt60l6sHFgGXcts6Jc0ue2loWPcEJ2g0jn9W5x3T4sV4xG0LLot62a6VWLqx%2FaDMLP%2B9lCCUKaW9IcYZECDQ%3D%3D
Most differences are the headers, most of them I don’t expect to make a difference, except one: Cookie.
Does the site require to login/authenticate? Cookies are often used with that, I I see none in Unity.
Also, both URL and ssl parameter are different (ssl differs not only in value, but also in length, perhaps something to look into?). Maybe they are supposed to, but in general you should be aiming to replicate things as close as possible.
1 Like
Okay, I made it. 
The problem was the Content-Type. All I had to add was www.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Thank you very much, Aurimas-Cernius!