Search Unity

Best HTTP Released

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

  1. h_kishi

    h_kishi

    Joined:
    Jun 9, 2015
    Posts:
    5
    When UseStreaming is true, it seems gzip decoding does not work.
    Does BestHttp support to use both UseStreaming=true and gzip encoding at the same time?
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @h_kishi: There are no on-the-fly decoding now, uncompressing done once when the full response downloaded. I want to improve on this, but currently you have to do it manually or you can send an "Accept-Encoding: identity" header to disable gzipping.
     
  3. suntabu

    suntabu

    Joined:
    Dec 21, 2013
    Posts:
    77
    @BestHTTP
    I'm using the v1.7 BestHTTP Pro version, but while I playing my game through the net shared from my computer's wifi, the connect timeout error happened always.
    Do you know the reason and please help?
    Thanks
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @suntabu: Can you share more details about you home network? Is there any proxies? Can you reach the target web service from the same device that the game is running on?
    Also, can you try it with a more recent version of the plugin?
     
  5. suntabu

    suntabu

    Joined:
    Dec 21, 2013
    Posts:
    77
    @BestHTTP
    Thanks for replying, I've updated to the latest version and the problem still exists.
    I am sorry for that I am a network newbie, so could you tell me what I should share exactly?
    I know that I am not using any proxies and I could reach the target web service from the same android phone by chrome browser, but the game could not.

    By the way with the latest version BestHTTP, our game's web request response much faster(not through pc's wifi) and thank you for what you have done~
     
  6. Namke

    Namke

    Joined:
    Mar 21, 2013
    Posts:
    6
    @BestHTTP
    I just purchase is package, open the sample and run, both wechat and weplay spawn same error
    "Err [HandshakeData]: Handshake request failed with error: Method not found: 'Org.BouncyCastle.Crypto.Tls.LegacyTlsClient..ctor'. at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0 "

    Is there are anything wrong?
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @suntabu: Unfortunately I'm in the dark with your issue too. I can't reproduce it, and haven't heard about similiar issues.
     
  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Namke: Hmm, what version of Unity are you using?

    Edit: Quickly tried out with Unity 4.6, 5.0.2 and 5.1, they run the samples fine.
     
    Last edited: Jun 11, 2015
  9. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    215
    Hi BestHTTP Dev,

    Websockets - Socket.io should work in WebGL?
     
  10. inlycat_unity

    inlycat_unity

    Joined:
    Dec 12, 2014
    Posts:
    2
    @BestHTTP
    I'm suntabu(@suntabu ), this is my company account which purchased BestHTTP pro. My pc connect to router by wire and share the net using 360WIFI(http://wifi.360.cn/). no proxies, no vpn
    Could you tell me some possible reasons leading to this problem or something I could try to verify anything you want to know? Thanks~~
     
  11. tungchengvn

    tungchengvn

    Joined:
    Sep 30, 2014
    Posts:
    13
    Does BestHttp's websocket support connection with cookies?
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Onsterion: WebGL builds are not supported yet.
     
  13. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @inlycat_unity: I will look into this 360WIFi, thanks. I think the best aproach of the problem currently, that it blocks the requests somehow...
     
  14. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @tungchengvn: Yes. You can access the internal request of the WebSocket and you can add cookies to the request. Also, it will use previously received cookies by the server automatically.
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @inlycat_unity: Tried out this 360WIFI and was able to reproduce it. But it think it failed to connect becouse while the signal strength was reported as strong, connecting to this wifi was failed a lot. Also, i see a lot that my device disconnected from the wifi and tried to reconnect to it.
    While these connection anomalies were there, the plugin failed to connect to the remote servers numerous times. After some time, the device was able to estabilish a reliable connection to this wifi hotspot, and suddenly all of the requests succesfully finished.
     
  16. inlycat_unity

    inlycat_unity

    Joined:
    Dec 12, 2014
    Posts:
    2
    Thanks for replying ,but how to solve this as this 360WIFI is very popular in my country and many player complained this network problem, I could send the same request successfully which from chrome browser and other apps work fine.
     
  17. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @inlycat_unity: Generally, you can do the following:
    • Increase the ConnectTimeout to one minute. It will let the tcp packets to reach the server and will have enough time for an answer. This will help only if the device didn't disconnects from the wifi. With high or very hight packet drop rate it may go through.
    • Retry the request on timeout errors.
    • You may want to increase the request's Timeout too. It's default to 1 minute, but you may want to double it. But it depends on how many data the server sends.

    Code (CSharp):
    1. var request = new BestHTTP.HTTPRequest(new Uri("http://server.com"), (req, resp) =>
    2.     {
    3.         switch (req.State)
    4.         {
    5.             // The request finished without any problem.
    6.             case BestHTTP.HTTPRequestStates.Finished:
    7.                 if (resp.IsSuccess)
    8.                 {
    9.                     // TODO
    10.                 }
    11.                 else
    12.                     UnityEngine.Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    13.                                                     resp.StatusCode,
    14.                                                     resp.Message,
    15.                                                     resp.DataAsText));
    16.                 break;
    17.  
    18.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    19.             case BestHTTP.HTTPRequestStates.Error:
    20.                 UnityEngine.Debug.LogError("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    21.                 break;
    22.  
    23.             // The request aborted, initiated by the user.
    24.             case BestHTTP.HTTPRequestStates.Aborted:
    25.                 UnityEngine.Debug.LogWarning("Request Aborted!");
    26.                 break;
    27.  
    28.             // The request didn't finished in the given time.
    29.             case BestHTTP.HTTPRequestStates.TimedOut:
    30.                 UnityEngine.Debug.LogWarning("Processing the request Timed Out!");
    31.                 break;
    32.  
    33.             // Ceonnecting to the server is timed out.
    34.             case BestHTTP.HTTPRequestStates.ConnectionTimedOut:
    35.  
    36.                 // Re-send the request.
    37.  
    38.                 int retryCount = (int)req.Tag;
    39.                 if (++retryCount < /*MaxRetryCount*/ 6)
    40.                 {
    41.                     req.Tag = retryCount;
    42.                     req.Send();
    43.                 }
    44.  
    45.                 break;
    46.         }
    47.     });
    48.  
    49. request.ConnectTimeout = TimeSpan.FromMinutes(1);
    50. request.Timeout = TimeSpan.FromMinutes(2);
    51.  
    52. // Retry count
    53. request.Tag = 0;
    54.  
    55. request.Send();
     
  18. illuminat

    illuminat

    Joined:
    Jul 2, 2014
    Posts:
    40
  19. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @illuminat: In short: the plugin will wok fine when no keep-alive received.

    By default the plugin will reuse the connection, and will close the connection when it's receives a "Connection: close" header for its Keep-Alive request.
     
  20. illuminat

    illuminat

    Joined:
    Jul 2, 2014
    Posts:
    40
  21. Sylafrs

    Sylafrs

    Joined:
    Jun 25, 2013
    Posts:
    65
    Issue :

    On Android :​

    An exception was thrown by the type initializer for System.Net.Sockets.Socket
    at SocketEx.TcpClient.Init (AddressFamily family) [0x00000] in <filename unknown>:0
    at SocketEx.TcpClient..ctor () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.Connect () [0x0003c] in C:\HotProjects\Maif\Test_imetrik\Assets\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:436
    at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x0008a] in C:\HotProjects\Maif\Test_imetrik\Assets\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs:201

    Solution :

    Player settings > Other Settings > Optimization > Stripping Level* : Disabled.​
     
  22. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Getting this aswell

    1.8.0 installs with no issues
    Remove 1.8.0 and try 1.8.1 and get the same eg

    BestHTTP/HTTPConnection.cs(584,71): error CS1729: The type `Org.BouncyCastle.Crypto.Tls.LegacyTlsClient' does not contain a constructor that takes `4' arguments

    On Unity 5.1.0p1

    Note: In iOS platform in Unity aswell
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @KB73 : The /Assets/Plugins folder contains a TcpClientImplementation.dll. Please remove it, and try to import the new package again. There were api changes, but seems the new dll doesn't imported, or Unity doesn't import it.
     
  24. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Thanks for the prompt reply.
    There was an old dll hanging around, 3 of the errors disappeared
    Still have one...

    Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs(20,7): error CS0246: The type or namespace name `Org' could not be found. Are you missing a using directive or an assembly reference?
     
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @KB73: A TcpClientImplementation.dll must be in the /Assets/Plugins/ folder.
     
  26. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    No dice still, it's like something is stopping the process. Simply installing 1.8.1 does not create a TcpClientImplementation.dll in the plugins folder.

    Still getting the compile error. on the previous post, i can only assume the dll isn't copied/created until that process is complete?

    Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs(20,7): error CS0246: The type or namespace name `Org' could not be found. Are you missing a using directive or an assembly reference?
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @KB73: Really strange.
    This morning tried the whole upgrade process from 1.8.0 to 1.8.1. While it was a success for me, as you already know sometimes can fail somehow. And now it's especially strange that no dll created.
    The whole package is just an archive, unity uncopresses new and selected files.

    You might try to create a new project, and import the package there. Then you can copy the /Best HTTP (Pro)/ and /Plugins/ folder from there to the 'old' project.
     
  28. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Very bizarre, fresh project with a unity package, still occurs.
     
  29. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    I notice in the downloads, 1.8.1 is 4.2Mb and the 1.8.0 is 6.7Mb, they are also named slightly differently ( BestHttp1.8.1.unitypackage vs BestHTTP-Pro-1.8.0), i'll check with the person who downloaded it..
     
  30. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    If i just open up the package and look inside, 1.8.0 has the Plugins/.dll and the 1.8.1 that i was given, does not. I'll make sure that we grabbed the right version, perhaps the basic version was downloaded from the store by mistake.
     
  31. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Ok problem solved, the package wasn't re-exported correctly after it was downloaded and didn't have the missing .dll.
    Thanks for the help.
     
  32. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @KB73

    Hmm, good to know that this can happen and I'm happy that it's solved now.
     
  33. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    So new project, installs fine

    Current project, fails with 8 compile errors now
    Assets/Best HTTP (Pro)/BestHTTP/SignalR/Transports/ServerSentEventsTransport.cs(68,25): error CS0123: A method or delegate `BestHTTP.SignalR.Transports.ServerSentEventsTransport.OnEventSourceMessage(BestHTTP.ServerSentEvents.EventSource, Message)' parameters do not match delegate `BestHTTP.ServerSentEvents.OnMessageDelegate(BestHTTP.ServerSentEvents.EventSource, BestHTTP.ServerSentEvents.Message)' parameters

    There are no references to anythign BestHTTP anywhere prior to the install.
    This is an iOS project.
     
  34. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    FYI, i deleted anything to do with SignalR in the package and it compiled.
     
  35. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @KB73:
    Seen that kind of error, but doesn't found that mail now. If i remember right, a Message class was already defined in the global namespace.
     
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    It seems Message as a class name is very popular. :)
    Just changed it that all occurencies are qualified by its namespace to avoid this problem.
     
  37. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    cool, thanks :)
     
  38. asset-mania

    asset-mania

    Joined:
    Dec 17, 2013
    Posts:
    3
    Hi,

    How can I detect "SslPolicyErrors" to ValidateServerCertficate.

    like RemoteCertificateValidationCallback

    Code (CSharp):
    1. private static bool ValidateServerCertficate(
    2.         object sender,
    3.         X509Certificate cert,
    4.         X509Chain chain,
    5.         SslPolicyErrors sslPolicyErrors)
    6. {
    7.     if (sslPolicyErrors == SslPolicyErrors.None)
    8.     {
    9.         // Good certificate.
    10.         return true;
    11.     }
    Thanks
     
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @asset mania: There is a CustomCertificationValidator event in the HTTPRequest that is called from the RemoteCertificateValidationCallback, however the sslPolicyErrors are left out from the arguments. I left it out becouse it was very unreliable, it's remained SslPolicyErros.None on invalid certs too..

    I would recommed to switch to the alternete ssl handler, and write a custom verifier.
     
  40. EddieSpengler

    EddieSpengler

    Joined:
    Sep 8, 2014
    Posts:
    5
    I'm having an error where I occasionally get a null response. It was working fine over http but having changed to https it seems to happen pretty regularly and not often in the same place. I get the error instantly, it almost seems like it's skipping straight past the request and firing the callback right away without a response.

    I tried to look in to the request.Exception but I get an 'Array index out of range' error. Any suggestions or ideas would be greatly appreciated.
     
  41. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @EddieSpengler: Without a stack trace, i can think only one place where it should throw an "Array index ..." exception. It's generated when the server closes the tcp channel, and the plugin doesn't know about it.

    While a a stack trace would be welcome, you can try out these things:
    • You can try out the alternate ssl handler by setting the request's UseAlternateSSLHandler to true. It will skip the mono implementation and will use the bundled Bouncy Castle's. It's a more advanced implementation and supports Server Name Indication too.
    • You can try to disable the keep alive mechanism by setting the requests' IsKeepAlive property to false. It will not wait until the server unexpectedly closes the connection.
    • You can decrease the HTTPManager.MaxConnectionIdleTime, to 10-15 sec(HTTPManager.MaxConnectionIdleTime = TimeSpan.FromSeconds(10) ; ). It will close the connection when no request sent in the given time.
     
  42. asset-mania

    asset-mania

    Joined:
    Dec 17, 2013
    Posts:
    3
    thank you for reply
    I'm not sure about X509CertificateStructure and
    I was able to find X509Certificate articles, but was not able to find X509CertificateStructure articles

    Please tell me url of the sample if you know.

    thanks
     
  43. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @asset mania: Unfortunately this is an area where I'm very unexperienced too, but maybe @codeStrider can help how to write a working validator.
     
  44. EddieSpengler

    EddieSpengler

    Joined:
    Sep 8, 2014
    Posts:
    5
    @BestHTTP the MaxConnectionIdleTime idea seems to have fixed it. Thanks.
     
  45. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    @BestHTTP Everything is working great so far, (thank you!) though I'm stuck on how to parse strings from lists within an object received.
    For example, how would I get the "answers" from the following API code?
    {"name":"Object01","description":"An object","id":2,"question":"What is 1 + 1","user":13,
    "answers":[{"text":"2","correct":true,"id":4},{"text":"11","correct":false,"id":5},{"text":"200","correct":false,"id":6}]
    ,"active":false},
    I am able to get the "name" and "description" and so forth, but the List (nested objects?) doesn't turn the data into strings with the code I've been using so I need some help with that, please!
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan: You can use the bundled json parser if you wish. Using it you would write something like this:
    Code (CSharp):
    1. string jsonText = @"{""name"":""Object01"",""description"":""An object"",""id"":2,""question"":""What is 1 + 1"",""user"":13, ""answers"":[{""text"":""2"",""correct"":true,""id"":4},{""text"":""11"",""correct"":false,""id"":5},{""text"":""200"",""correct"":false,""id"":6}] ,""active"":false}";
    2. var decoded = BestHTTP.JSON.Json.Decode(jsonText) as Dictionary<string, object>;
    3.  
    4. Debug.Log(decoded["name"]);
    5.  
    6. var answersList = decoded["answers"] as List<object>;
    7.  
    8. for (int i = 0; i < answersList.Count; ++i)
    9. {
    10.     var answer = answersList[i] as Dictionary<string, object>;
    11.  
    12.     Debug.Log(string.Format(" Answer Id: {0} Text: '{1}' Correct: {2}", answer["id"], answer["text"], answer["correct"]));
    13. }
    14.  
     
  47. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    Thank you so much, that worked perfectly for what I needed! =D
     
  48. Alcaros

    Alcaros

    Joined:
    Jul 4, 2013
    Posts:
    2
    I Import package version 1.8.1. and get this error.

    Assets/Best HTTP (Pro)/BestHTTP/ServerSentEvents/EventSourceResponse.cs(19,63): error CS0246: The type or namespace name `IProtocol' could not be found. Are you missing a using directive or an assembly reference?

    Where is the IProtocol interface file? I'm sure I import all of package files into a project.
     
  49. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Alcaros: It's in the HTTPResponse.cs. You should delete the /Best HTTP (Pro)/ folder and reimport the package.
     
  50. Alcaros

    Alcaros

    Joined:
    Jul 4, 2013
    Posts:
    2
    OK. It works! Thank you very much.