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
2
Question by ESG-Steven · Apr 20, 2017 at 05:36 PM · unity 5cloneonlinewebrequestwhy

Is it possible to either Clone or Re-Send a UnityWebRequest?

We've recently started using UnityWebRequests and something that it is lacking is some way to dictate how many retries it should do before failure, and a manual timeout timer.

No big deal, we'll just wrap it and have our own retries and timeout timer.

Except.... There is no way to Send a UnityWebRequest twice. That sucks, I guess we'll just allocate memory a bunch of times for retries. Fine. Except... There is no constructor that lets you copy one request's info into another.

Any suggestions that don't involve manually copying one request's data into another?

Comment
Add comment · Show 3
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 ESG-Steven · Apr 26, 2017 at 09:18 PM 0
Share

https://feedback.unity3d.com/suggestions/make-unitywebrequest-more-user-friendly

avatar image sandeepsmartest · Apr 27, 2017 at 04:42 AM 0
Share

Check out this link - How can I send and receive data to and from a URL, i.e. server side scripts, web services, etc?

Hope this may help you. Nsks

avatar image ESG-Steven sandeepsmartest · Apr 27, 2017 at 04:50 AM 1
Share

Thanks for the reply but that thread is unrelated. I am using UnityWebRequest, not WWW. I am successfully using UnityWebRequest to perform all HTTP requests. $$anonymous$$y question is about saving on allocations, removing ugly/bad code, and reducing the amount of work we have to do to add basic functionality around the UnityWebRequest.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by IshanCK · Apr 27, 2017 at 01:04 AM

Yeah you can do that

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 ESG-Steven · Apr 27, 2017 at 04:24 AM 5
Share

How is this an answer?

avatar image
0

Answer by Baltrisch · Jun 14, 2019 at 02:32 PM

i know it is 2 years later but, i didn't find other post about it. i didn't find a easier solution but came up with this:

 public struct sRequest {
     UnityWebRequest request;
     string url;
     WWWForm form;
 
     public sRequest(string url, WWWForm form) {
         this.url = url;
         this.form = form;
         request = null;
     }
     private IEnumerator Send() {
         request = UnityWebRequest.Post(url, form);
         yield return request.SendWebRequest();
         if(request.error != null) yield return Send();
     }
 }

This sends the request indefinitely, but you get the point.

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 Bunny83 · Jun 14, 2019 at 02:55 PM 0
Share

It's a bad idea to execute the coroutine recursively especially there's no reason to do that. Each coroutine will allocate a new coroutine and IEnumerator object. Since you build a chain of these objects none will be released until you break the recursion. You can simply do:

 private IEnumerator Send()
 {
     int count = 0;
     while (count < 10)
     {
         count++;
         request = UnityWebRequest.Post(url, form);
         yield return request.SendWebRequest();
         if(request.error == null)
         {
             // success
             break;
         }
     }
     // Error, no success after 10 tries
 }

Though I guess the OP wants to duplicate / reuse the webrequest because it's probably a bit more complex than just a form. $$anonymous$$aybe some custom request headers. Anyways all you have to do is store any relevant data inside that request class (which really should be a class and not a struct).

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

7 People are following this question.

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

Related Questions

UnityWebRequest seems to crash application when active on Application.Quit()? 1 Answer

How an Online Server Game Works? 1 Answer

Check if there is a host on a specific IP? 0 Answers

[Unet] Player object loses authority on scene switch 1 Answer

How to destroy a clone of an effect attached to an object? 1 Answer


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