Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by berkanmamak · Mar 09, 2018 at 06:56 AM · networkingwebglwebrequestrequest

New UnityWebRequest How Can I Handle the responses ??

Hello everyone, I want to change my old codes to new classes because I want to build project to WebGL

I was using, WWW class for post requests and get responses

Sample Code for old usage

  public IEnumerator SendRequest(string url, WWWForm form, ResponseMethod _responseMethod, bool callMethod = true)
     {
         WWW www = new WWW(url, form);
         MessageLog("Method name: " + _responseMethod.Method.Name);
 
         while (!www.isDone)
             yield return null;
 
         if (string.IsNullOrEmpty(www.error))
         {
             if (callMethod)
                 _responseMethod(www.text);
             else
             {
                 MessageLog("Error: " + www.error);
                 requestTryCount = 0;
                 ResponseTry(url, form, _responseMethod, callMethod);
             }
         }
         else
         {
             MessageLog("Error: " + www.error);
             requestTryCount = 0;
             ResponseTry(url, form, _responseMethod, callMethod);
         }
     }

But, since I want to change my request handling system as UnityWebRequest class.

I'm writing this code,

 public IEnumerator OnLoginButtonRelease()
     {
         WWWForm form = new WWWForm();
         form.AddField("api_key",ApiKey);
         form.AddField("l_username", UserNameInputField.text);
         form.AddField("l_pass", PasswordInputField.text);
         form.AddField("l_product", product);
         form.AddField("l_sp", serviceProvider);
 
         UnityWebRequest www = UnityWebRequest.Post(domainApiPrefix + "/Login/login2", form );
         yield return www.SendWebRequest();
                         
         if (www.isNetworkError || www.isHttpError)
         {
             Debug.Log(www.error);
             Debug.Log(form.data);
         }
         else
         {
             Debug.Log("Post request complete!" + " Response Code: " + www.responseCode);
         }
 
     }


I still could not figure out how can I get responses as text for new usage. I was using www.text property for older request system.

Pls help me.

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

1 Reply

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

Answer by berkanmamak · Mar 09, 2018 at 08:02 AM

I used DownloadHandler and it worked.

Here is my new code ;

 public IEnumerator OnLoginButtonRelease()
     {
         WWWForm form = new WWWForm();
         form.AddField("api_key",ApiKey);
         form.AddField("l_username", UserNameInputField.text);
         form.AddField("l_pass", PasswordInputField.text);
         form.AddField("l_product", product);
         form.AddField("l_sp", serviceProvider);
 
         UnityWebRequest www = UnityWebRequest.Post(domainApiPrefix + "/Login/login2", form );
 
         www.downloadHandler = new DownloadHandlerBuffer();
         
         yield return www.SendWebRequest();
 
         if (www.isNetworkError || www.isHttpError)
         {
             Debug.Log(www.error);
             Debug.Log(form.data);
         }
         else
         {
             Debug.Log("Post request complete!" + " Response Code: " + www.responseCode);
             string responseText = www.downloadHandler.text;
             Debug.Log("Response Text:" + responseText);
         }
     }
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

114 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

Related Questions

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

How do I retrieve a binary file with UnityWebRequest? 1 Answer

What is the ip when sending a webrequest in webgl build 1 Answer

UnirtyWebRequest.Post sending empty uploadHanlder.data 1 Answer

How to make multiple rooms with Unity and WebGL? 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