Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text return value to DownloadHandlerBuffer reponse #2

Closed
tomkail opened this issue Jan 26, 2023 · 10 comments · Fixed by #3
Closed

Add text return value to DownloadHandlerBuffer reponse #2

tomkail opened this issue Jan 26, 2023 · 10 comments · Fixed by #3
Assignees
Labels
bug Something isn't working

Comments

@tomkail
Copy link

tomkail commented Jan 26, 2023

When using the Post functions, DownloadHandlerBuffer is used for the downloadHandler. This results in text not being returned.
I'm not sure if this is by design or not?

@tomkail tomkail added the bug Something isn't working label Jan 26, 2023
@StephenHodgson
Copy link
Member

Hi @tomkail could you post an example of your code?

@StephenHodgson StephenHodgson self-assigned this Jan 26, 2023
@tomkail
Copy link
Author

tomkail commented Jan 26, 2023

Sure! Not much to it really:
await Rest.PostAsync(query, json, headers);
It's successful but the response body is null because the PostAsync function uses DownloadHandlerBuffer. On line 629 of Rest.cs you'll see that causes it to return null.

@StephenHodgson
Copy link
Member

StephenHodgson commented Jan 26, 2023

The download handler type is determined by the underlying webrequest

you may need to deserialize and/or reencode the string from the binary data.

@StephenHodgson StephenHodgson added question Further information is requested and removed bug Something isn't working labels Jan 26, 2023
@tomkail
Copy link
Author

tomkail commented Jan 26, 2023

Riiight. Makes sense. It's very awkward though! The standard way this type of request is returned is via text, right?

@StephenHodgson
Copy link
Member

I think it is determined by the returned content type of the response from the server.

@StephenHodgson
Copy link
Member

StephenHodgson commented Jan 26, 2023

If you have control of the server, change your MIME content type to json or text.

application/json
text/plain

@tomkail
Copy link
Author

tomkail commented Jan 26, 2023

Hm that might be true, but webRequest.downloadHandler?.text does contain the data I'm expecting, so in this case it feels like the plugin is getting in the way of the way UnityWebRequest is already working.

@StephenHodgson
Copy link
Member

Ah I see, sure let's add it to the return here

return new Response(true, null, webRequest.downloadHandler?.data, webRequest.responseCode);

case DownloadHandlerBuffer _:
    return new Response(true, webRequest.downloadHandler?.text, webRequest.downloadHandler?.data, webRequest.responseCode);

Is this what you're suggesting?

@tomkail
Copy link
Author

tomkail commented Jan 26, 2023

Yup!

@StephenHodgson StephenHodgson changed the title Text not returned from Post Add text return value to DownloadHandlerBuffer reponse Jan 26, 2023
@StephenHodgson StephenHodgson added bug Something isn't working and removed question Further information is requested labels Jan 26, 2023
@StephenHodgson StephenHodgson linked a pull request Jan 26, 2023 that will close this issue
@StephenHodgson
Copy link
Member

Give it about 5 min to build, then update to 1.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants