这是我的API请求
public IEnumerator Login(string bodyJsonString)
{
Debug.Log(bodyJsonString);
UnityWebRequest req = UnityWebRequest.Post("localhost:3000/login", bodyJsonString);
req.SetRequestHeader("content-type", "application/json");
yield return req.SendWebRequest();
if (req.isNetworkError || req.isHttpError)
{
Debug.Log(req.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
它返回错误状态代码500,并且在服务器上返回位置0“,”严重性“中的JSON中的错误意外令牌%>
这是我的协程电话
public void submitLogin() { _username = userInputField.GetComponent<InputField>().text; _password = passwordInputField.GetComponent<InputField>().text; Debug.Log("username" + _username); Debug.Log("password" + _password); string body = "{'username':'" + _username + "','password','" + _password + "'}"; //API Call authChexi = new Auth(); StartCoroutine(authChexi.Login(body)); }
让我知道您是否对如何处理我的表单有任何想法。谢谢
[这是我的API请求,公共IEnumerator登录(string bodyJsonString){Debug.Log(bodyJsonString); UnityWebRequest req = UnityWebRequest.Post(“ localhost:3000 / login”,bodyJsonString); ...
所以我已经更新了我的功能。我做了一些挖掘,终于解决了。我的错误确实是手动建立JSON。所以这是我的解决方案。