Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by nima8 · Jul 31, 2020 at 12:58 AM · androidwebrequesthttppost

Unity HTTP Post WebRquest not working on some Android Devices

I am having an issue with making post requests on some Android devices,

Here is my enumerator for web request

  [SerializeField] private Text _statusText;    //for debugin
  [SerializeField] private Text _donloadHandlerText;    //for debugin
  public IEnumerator GetEvent(string url, string bodyJsonString, System.Action callback)
  {
 
      print(bodyJsonString);
      var request = new UnityWebRequest(url, "POST");
      byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString);
      request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
      request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
      request.SetRequestHeader("Content-Type", "application/json");
      request.timeout = 10; //Setting the timeout request;
      yield return request.SendWebRequest();
      if (request.isNetworkError || request.isHttpError)
      {
          Debug.Log("Network Error: " + request.responseCode + request.error);
          _statusText.text = "Event Call Status: " + request.responseCode  + " " + request.error;//for debugin
      }
      else
      {
          Debug.Log("Status Code: " + request.responseCode);
          _statusText.text = "Event Call Status: " + request.responseCode;//for debugin
 
          //getting the body from call
          Debug.Log(request.downloadHandler.text);
          _donloadHandlerText.text = "Download Handler: " + request.downloadHandler.text;
          var data = request.downloadHandler.text;
          EventCallBack eventCallBack = EventCallBack.CreateFromJSON(data);
          callback(eventCallBack);
      }
  }

This code works perfectly fine on Unity Editor, iOS devices. However, here is the interesting part on Andriod devices the post request works fine on wifi network. But if the user switches to cellular mobile network on some Android phone I am not able to make any post-call.

I have checked to see if the application does have access to cellular mobile network

  if (Application.internetReachability == NetworkReachability.NotReachable)
  {
      //Change the Text
      _networkStatus.text = "NetWork Status: " + "Not Reachable.";
  }
  //Check if the device can reach the internet via a carrier data network
  else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
  {
      _networkStatus.text = "NetWork Status: " + "Reachable via carrier data network.";
  }
  //Check if the device can reach the internet via a LAN
  else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
  {
      _networkStatus.text = "NetWork Status: " + "Reachable via Local Area Network.";
  }

and turned out the application does have access to the cellular mobile network. I also wanted to see what happen to post-call on Andriod devices which are affected by this problem.

I get the status call 200 which means the call success but in the body, I get a strange html fragment and the most interesting part is that I don’t actually receive any call in the backend but somehow I get responseCode 200 from the webRequest.

 <!DOCTYPE html>
  <html lang="en"?
    <head>
        <meta charest="utf-8">

Anyone has any idea that can help, please let me know. I have tried everything to find out what is happening but no look so far.

Note: I am also aware that Andiond on higher API(28+) level block http call by default I have added <application android:usesCleartextTraffic="true> line to my Andiodmanifest. I don't think the problem is from the http call being blocked cause it works using WIFI on every Android, whatever causing this problem is related to Andriod cellular mobile network.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

284 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 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 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

Try catch alternative for HTTP request 1 Answer

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

WWW http request loads way to long on IOS 0 Answers

Posting JSON-RPC with WebRequest 0 Answers

Allowing users to post to their FB walls from within a Unity app 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