Closed RobertCow closed 6 months ago
Hey @RobertCow can you confirm that you can reach this URL from your app: https://api.natml.ai/health
. Try doing a GET request from your device. Here's a test script generated by ChatGPT:
public class GetRequestExample : MonoBehaviour
{
// The URL you want to send the GET request to
public string url = "https://api.natml.ai/health";
// Start is called before the first frame update
void Start()
{
// Start the coroutine to send the GET request
StartCoroutine(GetRequest(url));
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Send the request and wait for the response
yield return webRequest.SendWebRequest();
// Check for errors
if (webRequest.isNetworkError)
{
Debug.Log("Error: " + webRequest.error);
}
else
{
// Log the response text
Debug.Log("Received: " + webRequest.downloadHandler.text);
}
}
}
}
Hi @olokobayusuf, thank you for your help! But I can't reach that URL in my app. Here is the log:
Curl error 28: Failed to connect to api.natml.ai port 443 after 42082 ms: Timed out
Error: Request timeout UnityEngine.Debug:Log (object) GetRequestExample/<GetRequest>d__2:MoveNext () (at Assets/GameMain/Scripts/Utility/GetRequestExample.cs:27) UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
But it's work in the browser:
{ "message": "I'm alive ;)" }
What platform are you running this test on? And where are you based geographically?
What platform are you running this test on? And where are you based geographically?
Platform: Windows && Mac Addr: China, ShangHai
Try the following code which extends the timeout:
public class GetRequestExample : MonoBehaviour
{
// The URL you want to send the GET request to
public string url = "https://api.natml.ai/health";
// Start is called before the first frame update
void Start()
{
// Start the coroutine to send the GET request
StartCoroutine(GetRequest(url));
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Set timeout
webRequest.timeout = 20; // 20 seconds
// Send the request and wait for the response
yield return webRequest.SendWebRequest();
// Check for errors
if (webRequest.isNetworkError)
{
Debug.Log("Error: " + webRequest.error);
}
else
{
// Log the response text
Debug.Log("Received: " + webRequest.downloadHandler.text);
}
}
}
}
Thanks! It can work normally now.
Perfect. This timeout fix will be added upstream.
SocketException: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in <111da4cba18442e7addb95bcddc21c3b>:0 at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in <111da4cba18442e7addb95bcddc21c3b>:0 at System.Net.WebConnection+<>c.<Connect>b__16_1 (System.IAsyncResult asyncResult) [0x00006] in <111da4cba18442e7addb95bcddc21c3b>:0 at System.Threading.Tasks.TaskFactory
1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action
1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in <88e4733ac7bc4ae1b496735e6b83bbd3>:0 --- End of stack trace from previous location where exception was thrown ---at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x001e1] in <111da4cba18442e7addb95bcddc21c3b>:0 Rethrow as WebException: Error: ConnectFailure (由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
Curl error 56: Receiving data failed with unitytls error code 1048578 Curl error 65: necessary data rewind wasn't possible Scanning for USB devices : 6.047ms Scanning for USB devices : 4.828ms Android Extension - Scanning For ADB Devices 146 ms Scanning for USB devices : 10.879ms Android Extension - Scanning For ADB Devices 139 ms Scanning for USB devices : 10.032ms Scanning for USB devices : 8.818ms Attempted to call .Dispose on an already disposed CancellationTokenSource Android Extension - Scanning For ADB Devices 155 ms Scanning for USB devices : 9.869ms Android Extension - Scanning For ADB Devices 135 ms Attempted to call .Dispose on an already disposed CancellationTokenSource Android Extension - Scanning For ADB Devices 139 ms Scanning for USB devices : 9.007ms Scanning for USB devices : 18.805ms Scanning for USB devices : 14.684ms Scanning for USB devices : 9.475ms Curl error 65: necessary data rewind wasn't possible Scanning for USB devices : 9.356ms Scanning for USB devices : 11.091ms`