0

I have some problems with UnityWebRequest.

I have several URLs to communicating with my server. Some URLs working fine expectly and other few URLs not working expectly.

It's a weird thing that there is no error in any unity and my server. My server respond with status 200 normally, but Unity client cannot receive any data from the server. (And later showed unity editor curl error 42 callback aborted in console) So I had testing my server on POSTMAN, Restlet Client, Curl, and even testing Axios on javascript. and it's working perfectly. and I think response data size does not matter about this problem because other working URLs data is the much bigger than response data size

I don't know why UnityWebRequest cannot receive any data in some URLs responses.

My web server using spring framework and unity client version is 2019.2.12f1 and I tried 2019.3.0.f1 but it's not working too.

I think there is no matter about the server because the server respond with 200 and done with communication.

Thanks for reading my problem and please give me some advice about solving this problem.

UPDATE:

here is my request code

private IEnumerator SendPutRequest() {
    var req = new UnityWebRequest("not/wokring/uri") {
        downloadHandler = new DownloadHandlerBuffer(),
        uploadHandler = new             UploadHandlerRaw(Encoding.UTF8.GetBytes(requestBody)) {
                    contentType = "application/json"
                }
            };
    req.SetRequestHeader("Authorization", "ACCESS TOKEN");
    req.method = UnityWebRequest.kHttpVerbPUT;

    yield return req.SendWebRequest();

    Logger.Debug(this, req.downloadHandler.text);
}

UPDATE2:

Here is test calling other api (https://randomuser.me/api/)

    private IEnumerator SendTestRequest() {
            var req = new UnityWebRequest("https://randomuser.me/api/") {
                downloadHandler = new DownloadHandlerBuffer()
            };
            req.method = UnityWebRequest.kHttpVerbGET;

            yield return req.SendWebRequest();

            Logger.Debug(this, req.downloadHandler.text);
        }

and working fine Result

and not working request

here is request body json

[{'complex-data'}]

here is code

private IEnumerator SendBookResult() {
            var req = new UnityWebRequest("http://not/wokring/uri") {
                downloadHandler = new DownloadHandlerBuffer(),
                uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(bookSolveBody)) {
                    contentType = "application/json"
                }
            };
            req.SetRequestHeader("Authorization", Token);
            req.method = UnityWebRequest.kHttpVerbPUT;

            yield return req.SendWebRequest();

            Logger.Debug(this, req.downloadHandler.text);
}

and here is respond server logs

    2021-03-30 15:52:01.768 DEBUG [user-resource-service,141475988d7477c7,835066c63711dc29,true] 40897 --- [ctor-http-nio-4] o.s.w.s.adapter.HttpWebHandlerAdapter    : [9651973a-15] Completed 200 OK

Their is no result and get error enter image description here

and working url..

code

private IEnumerator SendBookProblems() {
            var req = new UnityWebRequest("http://wokring/uri") {downloadHandler = new DownloadHandlerBuffer()};
            req.SetRequestHeader("Authorization", Token);
            req.method = UnityWebRequest.kHttpVerbGET;
            yield return req.SendWebRequest();
            Debug.Log(req.downloadHandler.text);
}

result is working

Result

Josh lee
  • 1
  • 2

1 Answers1

0

Finally, I found the solution to my problem.

Just add these codes after create unity web request instance

req.chunkedTransfer = false;
req.useHttpContinue = false;

I don't know why it works after adding these codes.

However, I figured out to working expectly.

Josh lee
  • 1
  • 2