Search Unity

Best HTTP Released

Discussion in 'Assets and Asset Store' started by BestHTTP, Sep 11, 2013.

  1. AliAfshari

    AliAfshari

    Joined:
    Sep 12, 2014
    Posts:
    13
    It works fine but must change Player Settings\Other Setting\Api Compatibility Level from .Net 2 subset to .Net 2. otherwise a reflection error arises.

    Could you explain more about these two proprties:
    1- BestHTTP.HTTPManager.IsCachingDisabled
    2- BestHTTP.HTTPManager.Heartbeats

    In my usage i don't need any cache because all requests are dynamic. should i set BestHTTP.HTTPManager.IsCachingDisabled = false?

    and how should to use heatbeats to reduce thread usages?
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @AliAfshari

    1.) You can enable/disable caching globally. Caching, if possible for the platform is enabled by default. If it's disabled (or enabled) caching still can be enabled (or disabled) per-request by setting the HTTPRequest object's DisableCache. If you know that you don't need this feature, you can set BestHTTP.HTTPManager.IsCachingDisabled to false, or you can set the BESTHTTP_DISABLE_CACHING compile directive to not even compile caching code.

    2.) The HeartbeatManager is used by the plugin to minimize thread counts or the need of monobehaviours. There are certain tasks that may not need an update every frame, so they can subscribe until it needed than unsubscribe.
    For example the Socket.IO implementation subscribes when the protocol opens to detect connect timeouts. But, when it's connected, it will unsubscribe to minimize function calls.
     
  3. light530

    light530

    Joined:
    Aug 30, 2016
    Posts:
    12
    Hello
    I would like to know if I can access the downloaded assetbundles when the device is offline.
    The downloaded caches are renamed by the plugin so it may be difficult to know which one is the cache I need. And I also cannot get the caches by using the download process since it is offline.
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @light530

    If the server sent the response with 'Expires' and/or 'Max-Age' headers the plugin will serve any consecutive requests from its cache.

    So, for example if the server sends back the response with an "Expires: Fri, 14 Oct 2017 20:38:15 GMT" header, the plugin will not even try to touch the server for one year, so it will work offline too.
    The same applies to the 'Expires' header too.

    And it's totally transparent for you, you can use the very same request and don't have to write two case for the fresh download and for the cached one. However you have to make sure that server will send the proper headers.
     
  5. cemozturk

    cemozturk

    Joined:
    Sep 27, 2015
    Posts:
    27
    Hi,
    Best http pro with socket-io is a beautiful combination.
    I wrote a game on it and it runs perfect.

    But when i tried to upload to itunesconnect, in app review mode, it's rejected because of not connecting servers.

    To debug it, i printed the error to my internet-problem-scene and resubmit the app.

    Please check the returning screenshot.

    It says "Access Denied at System.net.sockets ..."

    Is it because the port that i'm using 3000 or something else ?

     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @cemozturk

    I have a patch for this, just drop me a mail to besthttp@gmail.com and I will send it to you.
    It would be in the next release that i wanted to upload this week, but came too many thing across me, so i had no time to make the bundles. :/
     
  7. cemozturk

    cemozturk

    Joined:
    Sep 27, 2015
    Posts:
    27
    i dropped :)
     
  8. cemozturk

    cemozturk

    Joined:
    Sep 27, 2015
    Posts:
    27
    @BestHTTP
    I'm waiting for the patch, when will you send it ? App review team is waiting for me :(
     
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
  10. cemozturk

    cemozturk

    Joined:
    Sep 27, 2015
    Posts:
    27
    Thank you ;)
     
  11. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    953
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @JohnGate

    With this request I received back the image it points to(after the redirect):
    Code (CSharp):
    1. Uri uri = new Uri("http://graph.facebook.com/v2.8/194890260937428/picture?type=large");
    2.  
    3. HTTPRequest request = new HTTPRequest(uri, (req, resp) =>
    4. {
    5.     switch (req.State)
    6.     {
    7.         // The request finished without any problem.
    8.         case HTTPRequestStates.Finished:
    9.             if (resp.IsSuccess)
    10.             {
    11.                 Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    12.  
    13.                 // TODO: Request finished. Process server sent data.
    14.             }
    15.             else // Internal server error?
    16.                 Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    17.                                                 resp.StatusCode,
    18.                                                 resp.Message,
    19.                                                 resp.DataAsText));
    20.             break;
    21.  
    22.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    23.         case HTTPRequestStates.Error:
    24.             Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    25.             break;
    26.  
    27.         // The request aborted, initiated by the user.
    28.         case HTTPRequestStates.Aborted:
    29.             Debug.LogWarning("Request Aborted!");
    30.             break;
    31.  
    32.         // Connecting to the server is timed out.
    33.         case HTTPRequestStates.ConnectionTimedOut:
    34.             Debug.LogError("Connection Timed Out!");
    35.             break;
    36.  
    37.         // The request didn't finished in the given time.
    38.         case HTTPRequestStates.TimedOut:
    39.             Debug.LogError("Processing the request Timed Out!");
    40.             break;
    41.     }
    42. });
    43.  
    44. request.Send();
    Can you share more about your setup? What version of the plugin are you using?

    You can also try to set the request.UseAlternateSSL to false:
    Code (CSharp):
    1. request.UseAlternateSSL = false;
     
  13. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    953
    You can also try to set the request.UseAlternateSSL to false:
    Solved the problem.

    I'm using BestHTTP Pro latest with Unity 5.4 on Android.
     
  14. W-R-E-C-K-T-A-N-G-L-E

    W-R-E-C-K-T-A-N-G-L-E

    Joined:
    Jun 20, 2016
    Posts:
    2
    Can you confirm that signalR will work on Android and iOS platforms?
    When SignalR 3 comes out will you add support for that as well?
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @W-R-E-C-K-T-A-N-G-L-E

    Yes, it must work on both Android and iOS.

    As soon as a testable version comes out I will start to work on the new SignalR version too. For now, it looks that the protocol will change a lot, so it might be possible that it will not be a quick/trivial task.
     
  16. W-R-E-C-K-T-A-N-G-L-E

    W-R-E-C-K-T-A-N-G-L-E

    Joined:
    Jun 20, 2016
    Posts:
    2
    Wow, that was quick. You can expect a purchase shortly then. ;)
     
  17. AliAfshari

    AliAfshari

    Joined:
    Sep 12, 2014
    Posts:
    13
    Hi
    I Have besthttp pro in my projects and it causes build time take long time at every simple changes on my code. Are there any way to build package code and import dll to unity?
     
  18. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @AliAfshari

    You can move the \Assets\Best HTTP (Pro)\ folder under \Assets\Standard Assets\ and/or use the bundled dlls in the \Assets\Best HTTP (Pro)\Precompiled.zip. In the last case, you have to delete the \Best HTTP (Pro)\BestHTTP\ folder.
     
  19. AliAfshari

    AliAfshari

    Joined:
    Sep 12, 2014
    Posts:
    13
    Hi
    After 15 second of internet connection looses and without any activity this errors appear


    these errors are printed on console about 900 time in 30 seconds and then following error printed and above errors stopped


    on android devices these prints cause heavy lags. Why these errors appear and how can prevent them?
     
  20. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @AliAfshari

    Sent a link to an updated package in private.
     
  21. AliAfshari

    AliAfshari

    Joined:
    Sep 12, 2014
    Posts:
    13
    Thanks problem solved
    Is there any way to check internet connection by besthttp package or it's better to use unity ping class?
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @AliAfshari

    I would recommend to use a 3rd party (Unity or Asset Store asset) solution for this.
     
  23. bromske

    bromske

    Joined:
    Sep 11, 2012
    Posts:
    28
    Hello, can i send simple udp messages with besthttp, sample?
     
  24. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @bromske

    No, you can't send UDP messages, sorry.
     
  25. dave_e3ct

    dave_e3ct

    Joined:
    Nov 7, 2016
    Posts:
    12
    Hi all,
    I'm having trouble with using Get with WebGL.
    Everything works correctly with Unity Editor, iOS and Android, but not WebGL.
    If I use:

    Code (CSharp):
    1. HTTPRequest request = new HTTPRequest(new Uri("https://<my website>/topic_scores?public_id=aab1213&topic_id=18"),
    2.             HTTPMethods.Get,
    3.             OnRequestFinished);
    4.         request.Send();
    in web GL, the callback never happens, but it does in the editor and iOS/Android.

    If I use the unity UnityWebRequest method:

    Code (CSharp):
    1. IEnumerator GetDataCoroutine()
    2.     {
    3.         using(UnityWebRequest www = UnityWebRequest.Get("https://<my website>/topic_scores?public_id=aab1213&topic_id=18"))
    4.         {
    5.             yield return www.Send();
    6.             Debug.Log("Request Finished! Text received: " + www.downloadHandler.text);
    7.         }  
    8.     }
    9.  
    then I get a response in both WebGL and the editor, so looks like my URL is formed correctly.

    Anyone come across a similar problem?
    Any help would be appreciated.
    Thanks,
    Dave
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
  27. dave_e3ct

    dave_e3ct

    Joined:
    Nov 7, 2016
    Posts:
    12
    The updated package fixes the issue - many thanks! :)
     
  28. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    82
    Hi All,

    We're using BestHTTP (Basic) to download a bunch of videos from Vimeo for offline playback in the app. We're targetting PC and iOs only with BestHTTP (Using the native android download manager to handle the download on Android.)

    As they're big we're using the resume functionality starting from the provided example. (setRangeHeaders) All works beautifully! However the download is very, very slow as opposed to downloading the same file in the browser. (factor 20 slower).

    Is this inherent to downloads started with setRangeHeader? Or is there some kind of bottleneck we can start looking for? Is it something to be expected or can it be fixed in some way?

    Thanks for any insights!
    Tom
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    Hi @Tom-Goethals ,

    I would recommend to use the LargeFileDownloadSample as a starting point. It's should be able to resume, and must be much much faster than sending out multiple requests with SetRangeHeaders.
     
  30. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    82
    Just to clarify, the LargeFileDownloadSample example is the one we started from. (it's using SetRangeHeader to allow the resume) we just uncommented the parts where it's writing to files.

    When i run the example in unity (out of the box) it takes 96 seconds to download the 100Mb file. In the browser it takes 6 seconds.

    Could it be that it's just not using the proxy? i feel like if I turn of my system proxy (thus surfing with the slower backup internet at work) and download the file in the browser it takes around the same time.
     
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @Tom-Goethals

    There is an example in the documentation purely based on multiple requests using range headers. That would be very, very slow.

    When streaming is used, with a quick network connection (or reading/streaming from the local cache) it would be able to consume a lot of memory by quickly allocating a lot of fragments in the memory. On a mobile device it can be problem, and would cause hard to debug crashes. To prevent this, the plugin will download and keep in memory as few fragments as it just can and will wait until they are consumed by a callback.

    By increasing the StreamFragmentSize property of the request, you can bypass this behavior more and more. With the default 4Kb of StreamFragmentSize, the plugin will wait more, but will consume less memory. If you set it, let's say 4 Mb, or even 10 Mb, you can achieve better throughput with the sacrifice of memory.
     
  32. ARLG

    ARLG

    Joined:
    Mar 5, 2015
    Posts:
    11
    Hi,

    I try to download big file (movie for exemple).
    When I don't turn off caching, the first download it's good, I have my file in HTTPCache and my file with the FileStream function to have directly my mp4. But when I quit the application and reload it, they are no downloads, or messages ...

    When I turn off caching, everytime I play the application, the file is downloading but application download from scratch the file ...

    How can I manage it to avoid a new download on the server if I have already download the file?

    Thanks !

    Code (CSharp):
    1. var request = new HTTPRequest (new Uri (_url), HTTPMethods.Get, (req, resp) => {
    2.  
    3.             if(contentLenght == 0f)
    4.             {
    5.                 if(resp.GetFirstHeaderValue("content-length") != null)
    6.                 {
    7.                     string bytesCount = resp.GetFirstHeaderValue("content-length").Replace(" bytes", "");
    8.                     contentLenght = float.Parse(resp.GetFirstHeaderValue("content-length"));
    9.                 }
    10.             }
    11.  
    12.             List<byte[]> fragments = resp.GetStreamedFragments ();
    13.  
    14.             if (fragments != null)
    15.             {
    16.                 using (FileStream fs = new FileStream (Application.persistentDataPath + "/" + Path.GetFileName(req.Uri.AbsolutePath), FileMode.Append))
    17.                 {
    18.                     foreach (byte[] data in fragments)
    19.                     {
    20.                         Debug.Log("(" + gameObject.name + ") Download fragments : " + data.Length + " bytes");
    21.                         RefreshUi(data.Length);
    22.                         fs.Write (data, 0, data.Length);
    23.                     }
    24.                 }
    25.             }
    26.  
    27.             if (resp.IsStreamingFinished)
    28.             {
    29.                 Debug.Log ("Download finished : " + req.Uri.ToString());
    30.                 Invoke ("WaitBeforeCloseTextureCache", 0.5f);
    31.             }
    32.         });
    33.  
    34.         request.UseStreaming = true;
    35.         request.DisableCache = true;
    36.         request.StreamFragmentSize = 1 * 1024 * 1024; // 1 megabyte
    37.         request.Send ();
     
    Last edited: Nov 18, 2016
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @ARLG

    Prior to 1.9.14 there were a bug where a cached entity deleted on startup.If you have version 1.9.13 or older, you should update the plugin from the Asset Store.

    When you turn off caching however, you have to check for the existence for the file, and if it's exists, you shouldn't start the download!
     
  34. Anton-Argunov

    Anton-Argunov

    Joined:
    May 2, 2014
    Posts:
    6
    Hello @BestHTTP

    We have issue with Mac Store build.

    Plugin doesn't work without permission:
    com.apple.security.network.server

    But UnityEngine.WWW works without that permission.

    Apple rejects our builds with that permission.
    Can you explain why plugin does not work without com.apple.security.network.server permission and how can we fix that?
     
  35. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @Anton-Argunov

    The default TcpClient class I used contained Bind calls to be able to accept connections. Removed these calls from one of the latest version, but to make sure you can proceed with your publishing sent you a link, so you can download a version that must work.
     
  36. accessdev

    accessdev

    Joined:
    May 9, 2012
    Posts:
    37
    Hello,

    when using socket.io + best http , is there an option to specifiy to flush socket after each emit or is it the default behavior? equivalent to the noDelay option server side?
     
  37. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @accessdev

    Both polling and websocket transports will flush the socket by default.
     
  38. li76168

    li76168

    Joined:
    Sep 7, 2014
    Posts:
    11
    Hello,

    I recently received this error "internal TLS error this could be an attack" on wss client.
    Some of my customers respond to connection problems, I think this is the point.
    What the error is? Please,help me. Thanks.
     
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @li76168

    When are you getting this error? When connecting, or after a successful connection while communicating with the server?

    This usually occurs when the plugin try to use connection closed by the server, and can be mitigated by lowering the connection reuse-time:
    Code (CSharp):
    1. BestHTTP.HTTPManager.MaxConnectionIdleTime = TimeSpan.FromSeconds(10);
     
  40. li76168

    li76168

    Joined:
    Sep 7, 2014
    Posts:
    11
    I got this error after a successful connection while communicating with the server,I am playing game then break.
     
  41. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    Hi,
    I just purchased Best HTTP pro. I wanted to implement signalR in Unity for webGL platform. I made a simple test scene to verify. It was working fine in editor but when tested in browser it is giving error. I'm getting this error after connection status changes to "negotiating".
    ObjectDisposedException : The Object was used after being disposed.

    Any suggestions on how to resolve above issue will be very helpful since it is very important for one of my projects which needs to be released for facebook canvas and it is based on signalR and rest api.
    bug.PNG

    I have attached unitypackage, it will give errors. You have to add BestHTTP pro v1.9.16 plugin to resolve missing code errors. Once you play, press space to see OnScreenLogger. Press key "A" to start connection with signalR. It works in editor but not in browser.
     

    Attached Files:

    Last edited: Dec 11, 2016
  42. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,111
    Hi!

    Im having an issue where I'm bringing back a response to my web servers request, on doing a debug log of the response.DataAsText its coming back with the correct response, either Match or None, but its not reading it in the IF statements and ignoring them. Any idea where I'm going wrong?

    Code (csharp):
    1.  
    2. void onRequestFinished(HTTPRequest request, HTTPResponse response)
    3.     {
    4.        
    5.              
    6.         if (response.DataAsText == "Match")
    7.             Application.LoadLevel ("mainmenu");
    8.         if (response.DataAsText == "None")
    9.                 notify.CallNotification2();  
    10.    
    11.     }
    12.  
     
  43. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    While waiting for the reply, I looked for more details on why it's happening. I found location of bug in HTTPRequest class. It seems "Headers" dictionary was throwing null reference exception.
    publicvoidEnumerateHeaders(OnHeaderEnumerationDelegatecallback,boolcallBeforeSendCallback)
    {
    ......
    if(callback !=null)
    foreach(var kvp in Headers)
    callback(kvp.Key,kvp.Value);
    }
     
  44. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    I solved this issue by adding additional null check to above code as
    "if(callback !=null && Headers!=null)"

    Now i am having some other issue i.e.
    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:54512/signalr/negotiate?tid=0&_=570050672&clientProtocol=1.5&connectionData=%5B%7B%22Name%22:%22roomHub%22%7D%5D. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

    I know it can't be CORS issue since CORS is properly setup on my back end. After i added customerrors code in webconfig at back end as

    <system.web>
    <customErrors mode="Off"/>
    </system.web>
    Now i'm getting more detailed log error and it is showing parse error in url after "%" symbol.
    So what i did is replaced all occurences of "25" in above url with empty string then i pinged this directly in browser
    "http://localhost:54512/signalr/negotiate?tid=0&_=570050672&clientProtocol=1.5&connectionData=[{"Name":"roomHub"}]"

    it is working now.

    Currently searching in code where query string is converted to query with additional "25"
     
    Last edited: Dec 11, 2016
  45. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @li76168
    It can be a
    1.) communication error between the client and the server. One of the peers or the underlying OS can close the connection when it decides that the TCP connection failed.
    2.) or a misconfigured server can abort the long running connection.
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @reddy36996

    Just sent a download link to you in private. I think I fixed the second issue too.
    Let me know how it works.
     
    reddy36996 likes this.
  47. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @julianr

    First, the response object can be null if something goes wrong. In this case it throws a NullReferenceException that the plugin will catch and log out. As a best practice you should write a callback like this:
    Code (CSharp):
    1. void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
    2. {
    3.     switch (req.State)
    4.     {
    5.         // The request finished without any problem.
    6.         case HTTPRequestStates.Finished:
    7.             if (resp.IsSuccess)
    8.             {
    9.                 Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    10.  
    11.                 // TODO: Request finished. Process server sent data.
    12.             }
    13.             else // Internal server error?
    14.                 Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    15.                                                 resp.StatusCode,
    16.                                                 resp.Message,
    17.                                                 resp.DataAsText));
    18.             break;
    19.  
    20.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    21.         case HTTPRequestStates.Error:
    22.             Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    23.             break;
    24.  
    25.         // The request aborted, initiated by the user.
    26.         case HTTPRequestStates.Aborted:
    27.             Debug.LogWarning("Request Aborted!");
    28.             break;
    29.  
    30.         // Connecting to the server is timed out.
    31.         case HTTPRequestStates.ConnectionTimedOut:
    32.             Debug.LogError("Connection Timed Out!");
    33.             break;
    34.  
    35.         // The request didn't finished in the given time.
    36.         case HTTPRequestStates.TimedOut:
    37.             Debug.LogError("Processing the request Timed Out!");
    38.             break;
    39.     }
    40. }
    If the response isn't null, it can contain something else that you expect(like an error page from the server), and because you don't have a fallback case, it will skip your cases.

    I would add some fallback with logging:
    Code (CSharp):
    1. void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
    2. {
    3.     switch (req.State)
    4.     {
    5.         // The request finished without any problem.
    6.         case HTTPRequestStates.Finished:
    7.             if (resp.IsSuccess)
    8.             {
    9.                 if (resp.DataAsText == "Match")
    10.                     Application.LoadLevel("mainmenu");
    11.                 else if (resp.DataAsText == "None")
    12.                     notify.CallNotification2();
    13.                 else
    14.                     Debug.LogError("Unexpected response from server: " + resp.DataAsText);
    15.             }
    16.             else // Internal server error?
    17.                 Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    18.                                                 resp.StatusCode,
    19.                                                 resp.Message,
    20.                                                 resp.DataAsText));
    21.             break;
    22.  
    23.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    24.         case HTTPRequestStates.Error:
    25.             Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    26.             break;
    27.  
    28.         // The request aborted, initiated by the user.
    29.         case HTTPRequestStates.Aborted:
    30.             Debug.LogWarning("Request Aborted!");
    31.             break;
    32.  
    33.         // Connecting to the server is timed out.
    34.         case HTTPRequestStates.ConnectionTimedOut:
    35.             Debug.LogError("Connection Timed Out!");
    36.             break;
    37.  
    38.         // The request didn't finished in the given time.
    39.         case HTTPRequestStates.TimedOut:
    40.             Debug.LogError("Processing the request Timed Out!");
    41.             break;
    42.     }
    43. }
     
    julianr likes this.
  48. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,111
    @BestHTTP - Thank you for a detailed example, much appreciated.
     
  49. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,111
    @BestHTTP - I tried your example, it returns the values correctly in the log (Match) and (None) based on the results it brings back, but it always goes to this

    Code (csharp):
    1.  
    2. Debug.LogError("Unexpected response from server: "+ resp.DataAsText);
    3.  
    Any idea what would be causing this? Even if I remove the code from the PHP script and just put Match or None in the first line so it will bring back the response, it still errors.

    I'm using Unity 5.4.2f1 - Tried it on both PHP 5.6 and 7.0 web servers.

    I placed this code in place of the above code to find out the error code

    Code (csharp):
    1.  
    2.  
    3.  Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    4.                                                 resp.StatusCode,
    5.                                                 resp.Message,
    6.                                                 resp.DataAsText));
    7.  
    8.  
    the error code came back was 200, which means transmission is OK on the HTTP level.

    Can you do a test your end?
     
    Last edited: Dec 12, 2016
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,402
    @julianr Can you send me a link that I can use to test?
     
    julianr likes this.