Last active
November 11, 2018 08:08
-
-
Save heartgamer/94b39cefeca73a1e38b2909f2fb0481b to your computer and use it in GitHub Desktop.
BestHTTP에서 timeout을 포함한 예외 핸들링 예시
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = new HTTPRequest(new Uri("http://yourserver.com/"), (req, resp) => { … }); | |
request.Timeout = TimeSpan.FromSeconds(10); | |
request.Send(); | |
A more complete example: | |
string url = "http://besthttp.azurewebsites.net/api/LeaderboardTest?from=0&count=10"; | |
HTTPRequest request = new HTTPRequest(new Uri(url), (req, resp) => | |
{ | |
switch (req.State) | |
{ | |
// The request finished without any problem. | |
case HTTPRequestStates.Finished: | |
Debug.Log("Request Finished Successfully!\n" + resp.DataAsText); | |
break; | |
// The request finished with an unexpected error. | |
// The request's Exception property may contain more information about the error. | |
case HTTPRequestStates.Error: | |
Debug.LogError("Request Finished with Error! " + | |
(req.Exception != null ? | |
(req.Exception.Message + "\n" + req.Exception.StackTrace) : | |
"No Exception")); | |
break; | |
// The request aborted, initiated by the user. | |
case HTTPRequestStates.Aborted: | |
Debug.LogWarning("Request Aborted!"); | |
break; | |
// Ceonnecting to the server timed out. | |
case HTTPRequestStates.ConnectionTimedOut: | |
Debug.LogError("Connection Timed Out!"); | |
break; | |
// The request didn't finished in the given time. | |
case HTTPRequestStates.TimedOut: | |
Debug.LogError("Processing the request Timed Out!"); | |
break; | |
} | |
}); | |
// Very little time, for testing purposes: | |
//request.ConnectTimeout = TimeSpan.FromMilliseconds(2); | |
request.Timeout = TimeSpan.FromSeconds(5); | |
request.DisableCache = true; | |
request.Send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment