이 함수는 localhost에서 동작하지 않습니다. 아직은 Coroutine 버전만 제공하므로 꼭 monobehaviour 안에서 StartCoroutine 안에 담아 사용하십시오. async 버전을 업데이트할 생각입니다.
// Get example
StartCoroutine(WebRequest(
"<http://localhost:3000/>",
XVerseRequestTypes.GET,
(data) =>
{
Debug.Log($"RESPONSE code:{data.ResponseCode}, length:{data.Length}");
Debug.Log($"RESPONSE BODY ---------------- ");
Debug.Log(Encoding.UTF8.GetString(data.Data));
},
(data) =>
{
Debug.Log($"RESPONSE FAIL code:{data.ResponseCode}, message:{data.Message}");
})
);
// Post example
StartCoroutine(WebRequest(
"<http://localhost:3000/>",
XVerseRequestTypes.POST,
(data) =>
{
Debug.Log($"RESPONSE code:{data.ResponseCode}, length:{data.Length}");
Debug.Log($"RESPONSE BODY ---------------- ");
Debug.Log(Encoding.UTF8.GetString(data.Data));
},
(data) =>
{
Debug.Log($"RESPONSE FAIL code:{data.ResponseCode}, message:{data.Message}");
}),
"User", "Alice", "PASS", "1234"
);
signature
public static IEnumerator WebRequest
(
string URL,
XVerseRequestTypes type,
Action<ResponseData> successHandler,
Action<FailResponseData> failHandler = null,
params string[] formData
)
url이 localhost일 경우에는 WebRequest함수가 동작하지 않습니다. 이 경우 아래와 같이 GetWebRequestLocal 함수를 사용. ms 단위의 timeout을 설정할 수 있습니다. signature 을 참고하세요.
string url = "<http://localhost:3000/>";
XVerseWeb.GetWebRequestLocal(url, (data) =>
{
Debug.Log(data.ResponseString);
},
(data) =>
{
Debug.Log(data.Message);
});

성공시

실패시
이 함수들은 웬만하면 fail하지 않도록 만들었습니다. fail이 발생할 시 failhandler가 적절한 처리를 해주어야 뒤쪽 로직에 잘못된 value가 전달되지 않습니다.
signature
public static void GetWebRequestLocal(
string URL,
Action<ResponseData> successHandler,
Action<FailResponseData> failHandler = null,
int timeOut = 30 * 1000
)