- Home /
Question by
S-Guertler · Oct 04, 2018 at 06:34 PM ·
webrequestphp
downloadHandler.text = "\u001f�\b"
Hello,
i try to POST a form to my php script which then returns "Hello" -> echo ("Hello");
But my downloadHander.text is always = "\u001f�\b"
It was working before i updated unity... Does anyone know what is wrong?
IEnumerator sendLogin()
{
WWWForm loginUser = new WWWForm();
loginUser.AddField("name", fieldUsername.text);
loginUser.AddField("password", fieldPassword.text);
UnityWebRequest download = UnityWebRequest.Post(url, loginUser);
yield return download.SendWebRequest();
if (download.downloadHandler.text == "Hello")
{
Debug.Log("Works");
}
else
{
Debug.Log(download.downloadHandler.text);
}
}
Comment
Best Answer
Answer by S-Guertler · Oct 07, 2018 at 01:34 PM
Answer: It was compressed in GZIP
Simply decrompress it whit this function:
static byte[] Decompress(byte[] gzip)
{
using (GZipStream stream = new GZipStream(new MemoryStream(gzip),
CompressionMode.Decompress))
{
const int size = 4096;
byte[] buffer = new byte[size];
using (MemoryStream memory = new MemoryStream())
{
int count = 0;
do
{
count = stream.Read(buffer, 0, size);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
return memory.ToArray();
}
}
}
And use like this:
byte[] decompress = Decompress(www.bytes);
//Convert to string
string text = System.Text.ASCIIEncoding.ASCII.GetString(decompress);
Thanks to StackOverFlow
Thank you very much for sharing your answer after fixing your problem. You saved me quite some time.