Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
  • Help Room /
avatar image
0
Question by francoenriquee5 · Jul 12, 2021 at 03:48 PM · wwwwebrequestwwwformform

I have some deprecated errors with WWW someone knows how to convert this lines and use UnityWebRequest instead of WWW

      /*this is obsolete use UnityWebRequest*/
     WWW www = new WWW("http://localhost:8888/action_login.php", form);
     yield return www;

     if (string.IsNullOrEmpty(www.error))
     {
         /*this is obsolete use UnityWebRequest*/
         if (www.text.Contains("invalid email or password"))
         {
             infoText.text = "Invalid email or password";
         }
         else
         {
             infoText.text = "Loggin Sucessful...";
         }

     }
     else
     {
         infoText.text = "Error Ocurred...";
     }
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

Answer by nratcliff · Jul 12, 2021 at 06:18 PM

It looks like you're making a POST request in the provided example. You can use UnityWebRequest.Post for this. There's a great example on the documentation for the method: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html

If your web service implements HTTP status codes properly you can check the value of the result property. This is the example from the docs:

 if (www.result != UnityWebRequest.Result.Success)
 {
     Debug.Log(www.error);
 }
 else
 {
     Debug.Log("Form upload complete!");
 }


I recommend you go with that approach because it's a bit more flexible/universal. If your service responds with a different message and you're checking the message exactly, then your login code could break. If you check the status code, then the actual message doesn't matter. You could even forward www.error right to the user so you don't have to worry about what the error message is.

If you really need to check the content of the response, you can use the attached downloadHandler to get the text: string message = www.downloadHandler.text

See the downloadHandler documentation for more info: https://docs.unity3d.com/ScriptReference/Networking.DownloadHandler.html

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
avatar image
0

Answer by francoenriquee5 · Jul 12, 2021 at 09:43 PM

Thanks a lot, Let me try 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 francoenriquee5 · Jul 12, 2021 at 11:23 PM 0
Share

I solved with this code, thanks a lot

 public class ServerManager : MonoBehaviour
 {
     public TMP_InputField inputEmail;
     public TMP_InputField inputPassword;
     public TextMeshProUGUI infoText;
 
     WWWForm form;
 
     public void RegisterButton()
     {
         infoText.text = "Processing registration...";
     }
 
     public void LogginButton()
     {
         infoText.text = "Logging In...";
         StartCoroutine(RequestLoggin());
     }
 
     IEnumerator RequestLoggin()
     {
         string email = inputEmail.text;
         string password = inputPassword.text;
 
         form = new WWWForm();
         form.AddField("email", email);
         form.AddField("password", password);
 
         using (UnityWebRequest www = UnityWebRequest.Post("http://localhost:8888/action_login.php", form))
         {
             yield return www.SendWebRequest();
 
             if (string.IsNullOrEmpty(www.error))
             {
                 if (www.downloadHandler.text.Contains("invalid email or password"))
                 {
                     infoText.text = "invalid email or password";
                 }
                 else
                 {
                     infoText.text = "loggin success";
                     Debug.Log(www.downloadHandler.text);
                 }
             }
             else
             {
                 infoText.text = "An error ocurred";
             }
 
         }
     }
 }

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

166 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

Related Questions

UnityWebRequest.Post() has multipart/form-data strangely formatted when sending request 5 Answers

UnityWebRequest returns an empty string 1 Answer

www request Error unity 2018 0 Answers

unity WebRequest - Windows security 0 Answers

WWW HTTP Post request only works on Android if i'm comnected to Wifi, not on cellular data 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