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
1
Question by Forrest-Trepte · Aug 31, 2016 at 05:37 AM · networkingwebrequesterror-handling

What is a good way to determine if a UnityWebRequest succeeded?

The samples in the manual show using UnityWebRequest.isError method. Unfortunately (see the docs for that field) isError returns false when the web server returns an error such as 404 Not Found.

What would be a good way to determine if your web request succeeded in returning data that you can use? I'm thinking of something like this:

     private bool IsFailedRequest(UnityWebRequest request)
     {
         return request.isError || (request.responseCode != (long)System.Net.HttpStatusCode.OK);
     }

But I'm concerned that there may be other success status codes that I should be checking for. Also, although I'm getting 200 (HttpStatusCode.OK) back from a successful UnityWebRequest.Get, the result from a successful UnityWebRequest.GetAssetBundle call is returning 0 (not a status code). Is there a better way to check for success?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Forrest-Trepte · Apr 19, 2017 at 06:24 PM

I found that sometimes success is returned as HttpStatusCode.OK and sometimes as 0. So far, handling it like this seems to produce the expected results:

     public static bool IsSuccess(this UnityWebRequest request)
     {
         if (request.isError) { return false; }
 
         if (request.responseCode == 0) { return true; }
         if (request.responseCode == (long)System.Net.HttpStatusCode.OK) { return true; }
 
         return false;
     }
 
Comment
Add comment · Show 1 · 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
avatar image xappsdev · Oct 19, 2017 at 03:24 AM 0
Share

Have implemented this solution in my UWR useage at work, I believe this to be current for the latest Unity version too. Rewarded/upvoted.

avatar image
1

Answer by ickydime · Nov 02, 2017 at 08:05 PM

isError is depreciated in Unity 2017.

Check for IsHttpError for HTTP responses other than 200 (success) and check isNetworkError for system errors.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding Custom Headers/Cookies to the UnityWebRequest.Post 1 Answer

Pass Headers and Arguments in UnityWebRequest POST Method Object 1 Answer

UnityWebRequest timing out ? Send() finishes but isDone = false 1 Answer

UnityWebRequest.POST calls to an HTTPS url throws "Unknown error" on specific device 0 Answers

UnityWebRequest ContentType not Overriding 4 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