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 fonkler · Jul 28, 2017 at 07:06 PM · networkinguser interfacewebservice

Login screen with HTTP GET request

Hi guys

I am trying to accomplish the following: have a UI where I can enter username and password. Upon pressing a button, a HTTP GET request should be made to a server to authenticate username and password. The server returns "0" or "1". The UI should then (as a start) just display "Login successful" or "Login failed".

I have the server running, I have the Unity UI running. I have also tried to find a solution myself, but I keep getting hung up on a) the old / new way of making HTTP requests b) coroutines

How do I make the HTTP GET request from the button in my UI?

Any helpful piece of code would be extremely appreciated.

Thank you very much in advance!

Comment
Add comment · Show 1
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 fonkler · Aug 02, 2017 at 11:29 AM 0
Share

So I have resolved this as follows. Not pretty, but at least functional. Out of my UI code, I start a coroutine which does the check on the backend. Inside the same coroutine, I get references to my UI objects (GameObject.find(xx)) and then modify the UI this way. Thanks for the inputs below, anyways.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Jul 28, 2017 at 08:55 PM

It's pretty simple, but you do need to put it in a coroutine function:

 WWW req = new WWW(url);
 yield return www;

 if(!String.IsNullOrEmpty(www.error))
 {
     String response = www.text;
     // do your logic with the response
 }
 else
 {
     //Handle error gotten from www.error
 }
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 fonkler · Jul 29, 2017 at 07:43 AM 0
Share

Thanks for your reply. However, the part with the coroutine is one thing that I struggle with. When I put this into a coroutine, I am not in the context / class / method of the button event handler anymore. So how would I, based on the result of the HTTP GET then update part of the UI?

avatar image
0

Answer by WazzaM · Jul 29, 2017 at 09:03 PM

Hey @Fonkler

I'm working on a service that will provide a nice Unity plugin for such a thing and a cloud service at the back end. The Unity code works and it's the cloud service I'm working on.

I've found that I'm much better off with UnityEngine.Networking.UnityWebRequest than the old WWW class. It's much more capable than the old WWW class. Handles all the HTTP methods and deals with HTTPS.

I'm sure you want to encrypt your users' credentials.

Also, when providing parameters to an HTTP(S) server, you probably want to use a POST.

The use of coroutines is for any moment where you wait for a response or event. You don't have_to use a coroutine but not doing so means stuttery frames.

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

95 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

Related Questions

Android client to C# server communication, how to?,How to have an Android app communicate with web server 2 Answers

UnityWebRequest and/or HttpWebRequest gives 403 on PUT 0 Answers

problems with multiplayer UI setup,Problems with full UI mobile game 0 Answers

Unity networking tutorial? 6 Answers

Pass Headers and Arguments in UnityWebRequest POST Method 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