Skip to content

In Unity SDK,Http return xml format string which cause can not covert json error #250

Open
@sasalicat

Description

@sasalicat

` if (req.isNetworkError || req.isHttpError)
#endif
{
var errorMessage = req.error;

                //
                // Parse JSON from response
                //
                if (!string.IsNullOrEmpty(req.downloadHandler.text))
				{
                    var data = Json.Deserialize<ErrorResponse>(req.downloadHandler.text);
                    if (!string.IsNullOrEmpty(data.error))
					{
                        errorMessage = data.error;
                        throw new HttpException((int)req.responseCode, errorMessage);
                    }
				}

                throw new HttpException((int)req.responseCode, errorMessage);
            }

            return req.downloadHandler.text;`

Here I show a part of function "public async Task Request(string uriMethod, string uriPath, Dictionary<string, object> jsonBody = null, Dictionary<string, string> headers = null)",which in class HTTP.In this part we can see that if error happen in requset, Http cover the req.downloadHandler.text into ErrorResponse by json,other case,It return req.downloadHandler.text directly.But I notice that req.downloadHandler.text is actually a XML format string,which obviously cannot covert by json,As a result,every time when http request fail a Unity error was triggered.
I try add Content-Type to header to order server return json format,but it doesn`t work.
Am I missing some setting for that?
in Unity SDK version:0.16.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions