0
\$\begingroup\$

I successfully coded my game to register a player with their 'username, password, email' After Registering id like a player to fill in their username & password and have it checked by the db. Upon 'Login' i ran into this :

"ArgumentException: Cannot create a multipart form data section without body data"

public class NetworkManager : MonoBehaviour { public void SignupComplete() { // Make sure nothing is blank if (usernameSignup.text == "" || passwordSignup.text == "" || passwordVerification.text == "" || age.text == "" || email.text == "") { return; } // Check if passwords match if (passwordSignup.text != passwordVerification.text) { return; } // Check Age if (int.Parse(age.text)< 13) { return; } // IF the client makes it this far, send their data to the website! Debug.Log("Processing Request"); StartCoroutine(ProcessRequest(usernameSignup.text, passwordSignup.text, DATA_URL_SIGNUP, age.text, email.text)); } // ERROR WHEN LOGIN "ArgumentException: Cannot create a multipart form data section without body data" public void LoginComplete() { if(usernameLogin.text == "" || passwordLogin.text == "" ) { return; Debug.Log("Please fill in all fields!"); } StartCoroutine(ProcessRequest(usernameLogin.text, passwordLogin.text, DATA_URL_LOGIN)); Debug.Log("Processing Request"); } IEnumerator ProcessRequest(string username, string password, string url, string age = null, string email = null) { List<IMultipartFormSection> form = new List<IMultipartFormSection>(); form.Add(new MultipartFormDataSection("username", username)); form.Add(new MultipartFormDataSection("password", password)); form.Add(new MultipartFormDataSection("age", age != null ? age : "0")); //age != null ? age : "0" form.Add(new MultipartFormDataSection("email", email == null ? "" : email)); UnityWebRequest www = UnityWebRequest.Post(url, form); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } else { Debug.Log("Signup completed!"); } } 
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Instead of List<IMultipartFormSection>, use WWWForm:

WWWForm form = new WWWForm(); form.Add("username", username)); form.Add("password", password)); form.Add("age", age != null ? age : "0")); form.Add("email", email == null ? "" : email)); UnityWebRequest www = UnityWebRequest.Post(url, form); //... 

See also: POST request documentation

\$\endgroup\$
7
  • \$\begingroup\$ WWW is depreciated no ? or is it just the WWWRequest... \$\endgroup\$ Commented Aug 13, 2021 at 23:28
  • \$\begingroup\$ WWWForm is not deprecated. You should get used to looking at the documentation, it can answer these questions for you. \$\endgroup\$ Commented Aug 14, 2021 at 0:04
  • \$\begingroup\$ Sorry... yea i really should \$\endgroup\$ Commented Aug 14, 2021 at 1:12
  • \$\begingroup\$ @IyaadSaley You originally marked this as the correct answer and then un-marked it; is there something you need clarification on? \$\endgroup\$ Commented Aug 14, 2021 at 2:01
  • \$\begingroup\$ Was up late last night, might of done it by accident. \$\endgroup\$ Commented Aug 14, 2021 at 12:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.