-1

these two errors keep showing up every time i try to send data from unity to my php file, i tried every fix i could find for 'curl error 51' so i am assuming the main issue is the second error.

Curl error 51: Cert verify failed: UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED

i have tried looking up this error but i couldn't find any answers.

InvalidOperationException: UnityWebRequest has already been sent; cannot begin sending the request again
UnityEngine.Networking.UnityWebRequest.SendWebRequest () (at <2424cac47b134bcb9980d5fdf8ea4441>:0)
AddScore+<Register>d__5.MoveNext () (at Assets/Scripts/AddScore.cs:30)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <e8645a79b0794e0e9a2b5bbff081b88a>:0)

here is the unity code as well

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;

public class AddScore : MonoBehaviour
{
    public InputField nameField;
    public GameObject Time;
    public GameObject ScoreText;

    public Button submitScore;

    public void InputScore()
    {
        StartCoroutine(Register());
    }

    IEnumerator Register()
    {
        WWWForm form = new WWWForm();
        form.AddField("name", "nameField.text");

        using (UnityWebRequest www = UnityWebRequest.Post("https://localhost/sqlconnect/addscore.php", form))
        {
            yield return www.SendWebRequest();

            {
                yield return www.SendWebRequest();

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    Debug.Log("Form upload complete!");
                    UnityEngine.SceneManagement.SceneManager.LoadScene(0);
                }
            }
        }
    }
}
jarlh
  • 42,561
  • 8
  • 45
  • 63
FaithlessS
  • 17
  • 5
  • `yield return www.SendWebRequest();` is present twice in your code. As the error says, you only need one. I assume the `UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED` error is because you're using https with a self-signed certificate or something else that is causing it to be untrusted. Perhaps try http first to narrow the problem down to your code or your configuration. – Retired Ninja Dec 17 '20 at 13:30
  • `yield return www.SendWebRequest(); { yield return www.SendWebRequest();` – derHugo Dec 17 '20 at 13:31
  • 1
    And then you need a certificate handler for https! See [UnityWebRequest with HTTPS/SSL](https://stackoverflow.com/a/55114077/7111561) – derHugo Dec 17 '20 at 13:33
  • Does this answer your question? [Unity TlsException: Handshake failed UNITYTLS\_X509VERIFY\_FLAG\_NOT\_TRUSTED](https://stackoverflow.com/questions/59945581/unity-tlsexception-handshake-failed-unitytls-x509verify-flag-not-trusted) – Beefster Dec 17 '20 at 20:44

1 Answers1

0

As the error message says, there is a WebRequest too much.

Instead of

IEnumerator Register()
{
    WWWForm form = new WWWForm();
    form.AddField("name", "nameField.text");

    using (UnityWebRequest www = UnityWebRequest.Post("https://localhost/sqlconnect/addscore.php", form))
    {
        yield return www.SendWebRequest();

        {
            yield return www.SendWebRequest();

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("Form upload complete!");
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }

use

IEnumerator Register()
{
    WWWForm form = new WWWForm();
    form.AddField("name", "nameField.text");

    using (UnityWebRequest www = UnityWebRequest.Post("https://localhost/sqlconnect/addscore.php", form))
    {
        yield return www.SendWebRequest();

        {

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("Form upload complete!");
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }
Rabennarbe
  • 42
  • 10
  • [Should I answer off-topic questions?](https://meta.stackexchange.com/questions/133552/should-i-answer-off-topic-questions) ;) This pretty much looks like a typo/accident-based problem and is therefore off-topic since it won't really help others in the future – derHugo Dec 17 '20 at 13:42