Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mikelmao · Jul 26, 2018 at 07:36 AM · networkingwebrequesthttp

Sending Unity Web Request Post returning empty from webhost

iv been stuck on this for a long time and I just can't seem to figure out what the problem is. This is working perfectly if im connecting to http://localhost/ but if I try it on my domain and host online then it suddenly doesn't return any information.

This is my httpPost class:

 public static IEnumerator httpPost(string path, string data, Action<APIHttpRequestModel> callback)
 {

     byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(data);
     var www = new UnityWebRequest(path, UnityWebRequest.kHttpVerbPOST);
     
     www.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
     www.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
     www.SetRequestHeader("Content-Type", "application/json");

     Debug.Log(www.uploadHandler.data); // This still returns the JSON string it's sending

     yield return www.SendWebRequest();

     if (www.isNetworkError)
     {
         Debug.Log("Something went wrong, and returned error: " + www.error);
         callback(new APIHttpRequestModel(false, 400, www.error));
     } else
     {
         Debug.Log(www.downloadHandler.text); // This returns empty because server isn't receiving any data
         if (www.responseCode == 200)
         {
             callback(new APIHttpRequestModel(true, www.responseCode, www.downloadHandler.text));
             Debug.Log(www.downloadHandler.text);
         }
         else
         {
             callback(new APIHttpRequestModel(false, www.responseCode, www.downloadHandler.text));
             Debug.Log(www.downloadHandler.text);
         }
     }
 }

I've tried debugging and these is what iv found so far:

  • If I try to Debug.Log() the www.uploadHandler.data it is populated with data.
    • If I output the request data on the server there is no data getting returned

    • If I try to connect to the same link, on the web host, through a REST Client, it's returning the proper data

    • It definitely is hitting the URL and path specified, but when I try to return the request data, it's just empty.

TL;DR: The code is hitting the endpoint, but not returning data (trying to output the data it sent) on a production server, if I do it locally it's working fine. If I try with a REST client to production server it's working fine aswell.

EDIT 1: I downloaded the latest version of unity and it seems to be working fine there, so it's something related to 2017.3.1f1

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Shameness · Jul 26, 2018 at 08:23 AM 0
Share

Hello, I guess it might be related with your production server. so may I suggest checking your hosted server's firewall, I am not pro, but lately I was fiddling with web server and checking firewall daily, there is lot of malicious requests has to be filtered away from legit requests. Sorry if this is not related at all.

avatar image mikelmao Shameness · Jul 26, 2018 at 09:12 AM 0
Share

The thing is it's working fine when i try with a RESTfull client like Postman, it's doing everything correctly there so it can't be a server related thing otherwise it would block the restfull client's request aswell.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mikelmao · Jul 26, 2018 at 02:00 PM

Apperantly this is a bug in some versions of Unity (I'm using version 2017.3.1f1)

The reason this is happening is because unity is sending the following header along with the request: "Transfer-Encoding: chunked" which many server's can't handle.

Adding www.chunkedTransfer = false; fixes this and will set it to the header to Content-Length

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use the new IMultipartFormSection in a UnityWebRequest.Post 2 Answers

Best cross platform Http Library? 1 Answer

UnityWebRequest: Out of memory 0 Answers

Multiple UnityWebRequest Headers returning 408 Timeout HttpError 0 Answers

OAuth 2.0 Capture Redirect 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges