this is my code im following creagines youtube tutorial and i cant get any printed logs from handler idk what im doing wrong. https://www.youtube.com/watch?v=utwSPVGZiiw&t=1s
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Web : MonoBehaviour
{
void Start()
{
//StartCoroutine(GetDate("https://localhost/BazaarApp/GetDate.php"));
//StartCoroutine(GetUsers("https://localhost/BazaarApp/GetUsers.php"));
}
//public void ShowUserItems()
//
// StartCoroutine(GetItemsID(Main.Instance.UserInfo.UserID));
//
IEnumerator GetDate(string uri)
{
using (UnityWebRequest www = UnityWebRequest.Get(uri))
{
www.downloadHandler = new DownloadHandlerBuffer();
// Request and wait for the desired page.
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
byte[] results = www.downloadHandler.data;
}
}
}
IEnumerator GetUsers(string uri)
{
using (UnityWebRequest www = UnityWebRequest.Get(uri))
{
www.downloadHandler = new DownloadHandlerBuffer();
// Request and wait for the desired page.
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
byte[] results = www.downloadHandler.data;
}
}
}
public IEnumerator Login(string username, string password)
{
WWWForm form = new WWWForm();
form.AddField("loginUser", username);
form.AddField("loginPass", password);
using (UnityWebRequest www = UnityWebRequest.Post("http://localhost/BazaarApp/Login.php", form))
{
www.downloadHandler = new DownloadHandlerBuffer();
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
Main.Instance.UserInfo.SetCredentials(username, password);
Main.Instance.UserInfo.SetID(www.downloadHandler.text);
//IFL OGGED IN CORRECTLY
if (www.downloadHandler.text.Contains("Wrong Credentials") || www.downloadHandler.text.Contains("Username does not exist"))
{
Debug.Log("Try Again");
}
else
{
Main.Instance.LoggedInTab.SetActive(true);
Main.Instance.Login.gameObject.SetActive(false);
}
}
}
}
public IEnumerator RegisterUser(string username, string password)
{
WWWForm form = new WWWForm();
form.AddField("loginUser", username);
form.AddField("loginPass", password);
using (UnityWebRequest www = UnityWebRequest.Post("http://localhost/BazaarApp/RegisterUser.php", form))
{
www.downloadHandler = new DownloadHandlerBuffer();
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
}
}
}
public IEnumerator GetItemsID(string UserID, System.Action callback){
WWWForm form = new WWWForm();
form.AddField("UserID", UserID);
using (UnityWebRequest www = UnityWebRequest.Post("http://localhost/BazaarApp/GetItemsID.php", form))
{
www.downloadHandler = new DownloadHandlerBuffer();
// Request and wait for the desired page.
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
string jsonArrayString = www.downloadHandler.text;
byte[] results = www.downloadHandler.data;
callback(jsonArrayString);
}
}
}
public IEnumerator GetItem(string ItemID, System.Action callback)
{
WWWForm form = new WWWForm();
form.AddField("ItemID", ItemID);
using (UnityWebRequest www = UnityWebRequest.Post("http://localhost/BazaarApp/GetItem.php", form))
{
www.downloadHandler = new DownloadHandlerBuffer();
// Request and wait for the desired page.
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log(www.downloadHandler.text);
string jsonArray = www.downloadHandler.text;
callback(jsonArray);
}
}
}
}
↧