Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Best HTTP Released

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

  1. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Hi Jason.

    I recently updated the BouncyCastle, maybe this caused the slowdown. I didn't experienced any slowdown, but I will try to look around in it.
    The mono-thing: one of the Unity update incorporated a patch for mono to handle newer cert(s). I think this is what you see now that a previous non-working ssl now working oob.
     
  2. fingersbleeding

    fingersbleeding

    Joined:
    Jun 10, 2013
    Posts:
    24
  3. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
  4. koeman

    koeman

    Joined:
    Oct 22, 2012
    Posts:
    2
    hi there, @BestHTTP,
    besthttp is great.
    i found a small problem that, bh can not work properly with visual studio in windows( error with "namespace org can not be found, namespaces webstocket can not be found", but i already import and regenerate the project for vs.). any solution? thanks.
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Hi koeman.

    Thank you for your compliment.

    In a new project imported the latest package, but i didn't received any error. Can you send me more detailes?
     
  6. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    We just switched our version to 1.6.2 because our last version was causing some other errors.

    Now when trying to build for Windows Phone 8 (ARM and x86), we are getting the following error:
    and several warnings, the first of which is:
    Is there any way to get a version that supports 8.0 as well?
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Hi chirhotec.

    You are absolutely right. It was a test dll and unintentionally released with 1.6.2. I will check how it got through to my release cycle, and post a new one asap.

    Edit: Here is the link for the new dll: http://1drv.ms/1vXDIAf Please try it, and let me know if it's still doesn't work.
     
    Last edited: Dec 12, 2014
  8. chirhotec

    chirhotec

    Joined:
    Mar 30, 2010
    Posts:
    47
    That did the trick! Thanks!
     
  9. AlessioPo

    AlessioPo

    Joined:
    Dec 29, 2014
    Posts:
    2
    It seems that the TimeOut property does not work, I've run a simple test using both the timeout properties:
    ConnectionTimeOut
    TimeOut
    When I set a ConnectionTimeOut to 5 milli ( for testing purpose as wrote in the documentation ) the connection gets immidiately in timeout but when I set the same timeout in the Timeout properties it does nothing and invoke the callback with the state Finished.
    I've even tested another case:
    Set a reasonable timeout like 10 secs then I've put a Thread.Sleep(20000) in the webservice and the HTTPRequest wait the sleep and invoke the callback with a finished state instead of breaking the execution at 10 secs with a Timeout state.
    I'm doing something wrong?
    Thanks
     
  10. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Here is a new HTTPConnection.cs, please overwrite the old one and try it again.
    Let me know how it's works.
     
  11. AlessioPo

    AlessioPo

    Joined:
    Dec 29, 2014
    Posts:
    2
    Thanks for your promt support!
    The given file unfortunately is not fully working but consider that I'm using GoodOldSocket instead of System.Net.Sockets.
    I've fixed it making the following change:
    HTTPConnecion.cs line 117, replaced
    StartTime = DateTime.MaxValue;
    with
    StartTime = DateTime.UtcNow;
    Everyting seems to work fine now, can you confirm that this will not affect other stuff?
    Thanks again!
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    This way it can interfere with the ConnectionTimeout value, as it will overlap with it.
    In the original version when the connection estabilished the StartTime will be set to the correct value(DateTime.UtcNow) and the countdown will start.
    In your version you have to subtract the actual time you connected to the client from the Timeout, and it can timeout before connected.
     
  13. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    v1.6.5 relesed with the following changelog:
    [Bugfix] POSTs with no data now will set the correct Content-Length header
    [Bugfix] Parallel POSTs to the same uri will no longer block each other​

    Socket.IO will be added to the supported protocols soon!
     
    cpx_matthew likes this.
  14. flxk

    flxk

    Joined:
    Aug 20, 2014
    Posts:
    9
    We're using custom DLLs to handle our backend code. Does the Pro version include a regular .NET 3.5 and Unity DLL to be used in custom projects? If not, does the code compile as regular .NET DLL, too (read: non-unity .NET)? Regards, Felix
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Hi Felix.

    The plugin has 3 layers.
    1. The first layer is a platform dependent dll(TcpClientImplementation.dll) that implements the TcpClient class(with some addition). There are 3 TcpClientImplementation.dll. One for Metro(Win8/WinRT), one for Windows Phone 8(.1) and one for all other platforms. These dlls doesn't depend on any Unity dll.
    2. The second layer is the core plugin. It has very little dependency on Unity. Most of it for Debug.Log, getting the Application.persistentDataPath and a WWWForm usage. And maybe some "using UnityEngine;" left on the begining of files accidentally. All of these can be removed very easily. Even the WWWForm usage, as it will not compile into WP8 builds.
    3. There is a class name HTTPUpdateDelegator that created dinamically. This is the only interface to Unity. It's purpose is to call some setup, and call the HTTPManager's OnUpdate function in every Update(). All callback functions will be dispatch in this OnUpdate function to avoid threading issues(so the plugin can be used easily). This class can be removed easily too, it's just 64 lines of code, truly just for calling some function. You can call these function manually after making them public.
    The Examples folder can be deleted, it doesn't contain any code that the plugin depends on.

    I think a dll can be made from the plugin easily with a little work.
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    So, in the next big update the Socket.IO implementation will be added.
    You can try out one of the example scenes here. This sample connects to the http://weplay.io/ server.

    I think ~99% of the Socket.IO features are implemented. I hope that I can push it to the Asset Store this month. Right now I'm writing the documentation, and if didn't see any bugs, or room for improvements, then I will not change the code.

    And some code sample from the example:
    Code (CSharp):
    1. void Start() {
    2.     // Set a custom SocketOptions
    3.     SocketOptions options = new SocketOptions();
    4.     options.AutoConnect = false;
    5.  
    6.     // Create the SocketManager instance
    7.     var manager = new SocketManager(new Uri("http://io.weplay.io/socket.io/"),
    8.                                     options);
    9.  
    10.     // Keep a reference to the root namespace
    11.    Socket = manager.Socket;
    12.  
    13.     // Set up our event handlers.
    14.     Socket.On(SocketIOEventTypes.Connect, OnConnected);
    15.     Socket.On(SocketIOEventTypes.Disconnect, OnDisconnected);
    16.     Socket.On("joined", OnJoined);
    17.     Socket.On("connections", OnConnections);
    18.     Socket.On("join", OnJoin);
    19.     Socket.On("move", OnMove);
    20.     Socket.On("message", OnMessage);
    21.     Socket.On("reload", OnReload);
    22.  
    23.     // Don't waste cpu cycles on decoding the payload,
    24.     // we are expecting only binary data with this event,
    25.     //  and we can access it through the packet's Attachments property.
    26.     Socket.On("frame", OnFrame, /*autoDecodePayload:*/ false);
    27.  
    28.     // Add error handler, so we can display it
    29.     Socket.On(SocketIOEventTypes.Error, OnError);
    30.  
    31.     // We set SocketOptions' AutoConnect to false,
    32.     // so we have to call it manually.
    33.     manager.Open();
    34. }
    35.  
    36. /// <summary>
    37. /// How many players are connected to the game.
    38. /// </summary>
    39. private void OnConnections(Socket socket, Packet packet, params object[] args)
    40. {
    41.   connections = Convert.ToInt32(args[0]);
    42. }
    43.  
    44. /// <summary>
    45. /// The server sent us a new picture to draw the game.
    46. /// </summary>
    47. private void OnFrame(Socket socket, Packet packet, params object[] args)
    48. {
    49.   if (State != States.Joined)
    50.     return;
    51.  
    52.   if (guiTexture.texture == null)
    53.   {
    54.     guiTexture.texture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
    55.     guiTexture.texture.filterMode = FilterMode.Point;
    56.   }
    57.  
    58.   // Load the server sent picture to our guiTexture
    59.   (guiTexture.texture as Texture2D).LoadImage(packet.Attachments[0]);
    60. }
    61.  
     
  17. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    I'm hitting a few very intermittent issues when pushing simple requests via the most recent versions of BestHTTP + Good Ol' Sockets. The same requests will work 999/1000 times but very rarely we're getting the error:

    "attempt to release a non-locked array"

    with stack:

    Code (CSharp):
    1.  
    2.   at A.b+a.A (Int32 ) [0x00000] in <filename unknown>:0
    3.   at A.b.A (Int32 , Int32 ) [0x00000] in <filename unknown>:0
    4.   at LostPolygon.System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    5.   at System.IO.Stream.ReadByte () [0x00007] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Stream.cs:168
    6.   at BestHTTP.HTTPResponse.ReadTo (System.IO.Stream stream, Byte blocker) [0x0001a] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:381
    7.   at BestHTTP.HTTPResponse.ReadHeaders (System.IO.Stream stream) [0x00015] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:247
    8.   at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x000dc] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPResponse.cs:196
    9.   at BestHTTP.HTTPConnection.Receive () [0x00038] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:487
    10.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00159] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:227
    11.  
    Has anyone ever seen this and any ideas on anything we can try to resolve?
     
  18. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    It looks like a Good ol' Sockets issue, you should try to ask about it in his forum. Hopefully he know what it is.

    However, I would try to lower the HTTPManager's MaxConnectionIdleTime too. There is a little chance that the server closes the tcp socket while the client tries to read from it. The default value is 1 or 2 minutes, you may try to set it to 30 sec:
    Code (CSharp):
    1. HTTPManager.MaxConnectionIdleTime = TimeSpan.FromSeconds(30);
     
  19. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    You were right, posted that error over on the Good Ol' Sockets forum and he rolled a new build out addressing the issue. We are now hitting another one though that appears to possibly just be in on the BestHTTP side. Error message is:

    Array index is out of range.

    Code (csharp):
    1.  
    2.  at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x00000] in <filename unknown>:0
    3.   at BestHTTP.HTTPConnection.Receive () [0x00000] in <filename unknown>:0
    4.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0
    5.  
    If it's any help, we are only seeing this only on a test machine that's under fairly heavy load. Any ideas would be appreciated.
     
  20. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Another error seems to also be periodically popping up on the same test machine:

    Input string was not in the correct format

    Code (csharp):
    1.  
    2.   at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
    3.   at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x00000] in <filename unknown>:0
    4.   at BestHTTP.HTTPConnection.Receive () [0x00000] in <filename unknown>:0
    5.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0
    6.  
     
  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    These are basically the same issues: the plugin can't understand the received data. The data here came from the underlaying .NET's NetworkStream, or in your case from the Good ol' Socket's NetworkStream implementation.
    These two errors are occurs when the plugin parses the version of the http response. This is the very first data that the client expects from the server: "HTTP/1.x" (where x is 0 or 1).

    Under heavy load there might some unexpected behavior from the undelaying os, tcp implementation. Partially received data, closing the tcp connection, etc. Or only part of the data received, when the tcp connection is closed.
    For GET requests there are a basic mechanism to retry the request, but for POSTs it's disabled. With unexpected data, the plugin will fail early.

    You can log out the version string that the plugin tries to parse in the HTTPResponse.cs after line 166. Maybe it will contain some valuable information.
     
  22. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Thanks for the response on this, I can actually switch a lot of my communication to GET requests and take advantage of your built in retries. I also get probably why you don't auto-retry POST's as that'd possibly introduce unexpected results on the server. In my implementation however I need to (or at least I prefer too) use posts as I'm pushing some rather large JSON payloads. In the event that the TCP stack bombs on us I'd gladly re-POST and I know I won't duplicate data or whatnot on the server.

    So long story short I guess... I've found that the above errors are evidently coming from a different stack than my active UI thread so I can't just wrap the request.Send() call in a try/catch block as these errors get thrown separately. Would you have any suggestion or recommendation however on how I could somehow catch these errors and intervene elegantly to re-send or address the POST issue somehow rather than a crash?
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    These errors should be caught by the plugin, and the request's State should be Error. If this correct, then you can try something like this in your callback function:

    Code (CSharp):
    1.  
    2. void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
    3. {
    4.     switch (req.State)
    5.     {
    6.         // The request finished without any problem.
    7.         case HTTPRequestStates.Finished:
    8.             if (resp.IsSuccess)
    9.             {
    10.                 // TODO: Process response's data
    11.                 Debug.Log("Request Finished Successfully! Data length: " + resp.Data.Length + " " + resp.DataAsText);
    12.             }
    13.             else
    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.  
    24.             int retryCount = req.Tag == null ? 0 : (int)req.Tag;
    25.             if (retryCount++ <= /*maxRetry:*/ 3)
    26.             {
    27.                 req.Tag = retryCount;
    28.  
    29.                 // send the request again.
    30.                 req.Send();
    31.             }
    32.             break;
    33.  
    34.         // The request aborted, initiated by the user.
    35.         case HTTPRequestStates.Aborted:
    36.             Debug.LogWarning("Request Aborted!");
    37.             break;
    38.  
    39.         // Ceonnecting to the server is timed out.
    40.         case HTTPRequestStates.ConnectionTimedOut:
    41.             Debug.LogError("Connection Timed Out!");
    42.             break;
    43.  
    44.         // The request didn't finished in the given time.
    45.         case HTTPRequestStates.TimedOut:
    46.             Debug.LogError("Processing the request Timed Out!");
    47.             break;
    48.     }
    49. }
    So, when there is an Error state, check how many times we retried the request, and send it again if we should. It should work just fine on GET and POST requests too.
     
    Last edited: Jan 23, 2015
  24. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Man.. I'm sorry. You are completely right. BestHTTP was catching this properly, I just wasn't handling the response states as robustly as I should have been (your example above helped a ton with giving me some ideas). I'm seeing one more anomaly on the Good Ol' Sockets side which I've just posted on their forum, but the BestHTTP layer seems to be working great. Thanks for your support on this.
     
  25. DeltaCygniLabs

    DeltaCygniLabs

    Joined:
    Nov 27, 2013
    Posts:
    14
    Hi BestHTTP!

    I'm still a very happy user of your package (Pro 1.6.5), thanks for the frequent updates and the good evolution!
    I have a question for you; I would like to do some streaming with a non-fixed fragment size, how should I do that?
    For example having a callback doing something every frame I'm receiving some bytes?
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Currently you can't do it. To be able to optimize as much as possible the buffer size is determined before the download starts. With variable sized fragments it would produce more GC allocations and with intensive thread synchronization it would add additional overhead to the cpu too.
    I recommend instead to set the request's StreamFragmentSize to a reasonable low value. It may produce a better balance between data-availabilty and overhead.
     
  27. DeltaCygniLabs

    DeltaCygniLabs

    Joined:
    Nov 27, 2013
    Posts:
    14
    Makes sense, thank you very much!
     
  28. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    We're now getting this error with the latest release of BestHTTP and Good Ol' Sockets ONLY (but consistently) on iOS:

    Code (csharp):
    1.  
    2. An exception was thrown by the type initializer for LostPolygon.System.Net.IPAddress
    3.  
    4.   at BestHTTP.HTTPConnection.Connect () [0x0003c] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:404
    5.  
    6.   at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x000b3] in /usr/local/pocketui/pe_unity_ngui/Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:192
    7.  
    8. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    9.  
    10. UnityEngine.Debug:LogError(Object)
    11.  
    Any ideas? (I also posted this on the Good Ol' Sockets forum if this is coming from their stuff)
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    I don't know what should be the probleme there, especially on iOS only.
    That constructor calls this code:
    Code (csharp):
    1.   public TcpClient()
    2.   {
    3.     Init(AddressFamily.InterNetwork);
    4.     client.Bind(new IPEndPoint(IPAddress.Any, 0));
    5.  
    6.     ConnectTimeout = TimeSpan.FromSeconds(2);
    7.   }
    8.  
    9.   private void Init(AddressFamily family)
    10.   {
    11.     active = false;
    12.  
    13.     if (client != null)
    14.     {
    15.       client.Close();
    16.       client = null;
    17.     }
    18.  
    19.     client = new Socket(family, SocketType.Stream, ProtocolType.Tcp);
    20.   }
    I think it should be an other Good ol' Sockets issue.
     
  30. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Once again you are correct. Good Ol' Sockets received a patch per our issue report and we are once again running on all platforms. Thanks!
     
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Great!
     
  32. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    In the meanwhile i was busy with Socket.IO, and today v1.7.0 uploaded to the Asset Store.
    The Socket.IO documentation however is already readable.

    The changelog of this release will be the following:
    General:
    • [Improvement] Improved cache compatibility
    • [Improvement] Improved proxy compatibility
    • [Improvement] HTTPRequest’s Send function will return the request to be able to chain some functions
    • [Improvement] Logger Added to the HTTPManager. Initially the Socket.IO implementation will use it.
    • [Improvement] HTTPManager’s MaxConnectionIdleTime lowered to 30 secs
    • [Improvement] HTTPRange’s ToString is overridden for quicker debugging
    • [Improvement] HTTPRequest’s GetRange function will no longer throw a null exception when there is no “content-range” header. It will return with null.
    • [Improvement] Removed uncessary exception logging in Directory platformsupport code
    • [Improvement] Renamed Tree class to remove Unity warning
    • [Bugfix] Internal buffer size for streaming set to the wrong value
    WebSocket:
    • [Improvement] Added some missing documentation
    • [Improvement] Removed the need of a new thread to send automatic pings
    • [Improvement] New Send function to send a portion of a byte array
    Socket.IO:
    • [New Feature] Initial Socket.IO release compatible with the latest official Socket.IO implementation
     
  33. Greire

    Greire

    Joined:
    Nov 14, 2014
    Posts:
    6
    hi,
    i'm trying simple test https.

    void Start () {
    string strUri = "https://google.com";
    HTTPRequest request = new HTTPRequest( new Uri( strUri ), (req, resp) => Debug.Log( resp ) );
    request.UseAlternateSSL = true;
    request.Send();
    }

    using UseAlternateSSL option, HTTPResponse object is always null.

    HTTPRequest object has no exception, no error, state is finished.

    what am i wrong?
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Hi Greire.

    What platform you experience this issue? Just tried it on Windows and Windows Phone and it's worked fine with the following code:
    Code (CSharp):
    1. void GoogleSSLTest()
    2. {
    3.     HTTPRequest request = new HTTPRequest(new Uri("https://google.com"), (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(resp.DataAsText);
    12.                     }
    13.                     else
    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.                 // Ceonnecting 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.         });
    41.     request.Send();
    42. }
     
  35. Greire

    Greire

    Joined:
    Nov 14, 2014
    Posts:
    6
    yes it works fine.

    add code
    request.UseAlternateSSL = true;
    before request.Send();

    is it work?

    Purchased BestHTTP Pro from AssetStore today.
    Unity's target platform is set to PC, Mac & Linux stnadalone.
    Run code at Unity(editor).
     
    Last edited: Jan 29, 2015
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    It's working with "request.UseAlternateSSL = true;" too, but you should use it only if you have problems with the default ssl handler.
    Also run from editor with pc target platform.
     
  37. Greire

    Greire

    Joined:
    Nov 14, 2014
    Posts:
    6
    at the first time. when i sent request, error acquires.

    error messages are listed below.

    TlsException: The authentication or decryption has failed.
    Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc)
    Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult)
    Rethrow as IOException: The authentication or decryption has failed.
    Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult)

    so i had to use higher version of TLS. my server is currently using TLS v1.2

    so I tested after setting UseAlternateSSL to true and sent request to our server.
    Then HTTPRequest object has no Exception and state is finished, but HTTPResponse object is NULL.

    In order to double check, I have tested request.send with google.com. But the outcome was still same.

    If I do not make any modification to your code, it runs fine.
    But if I set UseAlternateSSL to true, I get error messages stated below :

    Object reference not set to an instance of an object: at TestHttps.<GoogleSSLTest>m__58 (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse resp) [0x00028] in C:\Workspace\Assets\Scripts\TestCode\TestHttps.cs:35
    at BestHTTP.HTTPRequest.CallCallback () [0x0000b] in C:\Workspace\Assets\Best HTTP (Pro)\BestHTTP\HTTPRequest.cs:794
    UnityEngine.Debug:LogError(Object)
    BestHTTP.HTTPRequest:CallCallback() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:798)
    BestHTTP.HTTPConnection:HandleCallback() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPConnection.cs:594)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:388)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:49)

    Is there anything I and/or you are missing in order to solve this problem?
     
  38. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Might need to post your full TestHTTPS.cs content. The simple example you posted above does indeed work for me to Google also:
    Code (csharp):
    1.  
    2. void Start () {
    3.   string strUri = "https://google.com";
    4.   HTTPRequest request = new HTTPRequest( new Uri( strUri ), (req, resp) => Debug.Log( resp ) );
    5.   request.UseAlternateSSL = true;
    6.   request.Send();
    7. }
    8.  
    Does that exact code truly not work for you or where you reducing it down for your post? It seems something else must be going on.
     
  39. Greire

    Greire

    Joined:
    Nov 14, 2014
    Posts:
    6
    it is not reduced for the post. that simple code was everything.
    new empty scene, attach testHttps.cs to MainCamera object in hierarchy. and play.
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    As described in the documentation there are certificates that .net's SslStream can't handle. UseAlternateSSL will use an alternate one, that can handle a different set of certificates. But sadly, this two methodes can't cover all of them.

    Also, now i remember how we may see different results for the same page. If you are using an older version of Unity(<4.5.3) you may see the same certification failing while others can use it fine. As fingersbleeding wrote in a post above in 4.5.3 Unity incorporated a patch to be able to handle more types of certificates.

    But there are one more mistery, why you see different result for UseAlternateSSL too. :/
     
  41. Greire

    Greire

    Joined:
    Nov 14, 2014
    Posts:
    6
    thank you guys. it solved.

    delete BestHTTP(Pro) folder and import asset again, then works fine.
    still i don't know why. i think it is some kind of unity issue
     
  42. makeupsometthinglater

    makeupsometthinglater

    Joined:
    Jan 25, 2015
    Posts:
    2
    Hi Guys

    The asset is working great so far but I have one question. We are working with a webpage that automatically redirects to another page, we have no control over the redirection as it was programmed by another company. We want to ignore this redirection. Is there any way to do this?
     
  43. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    You can set how many redirects you want to support on the request:
    Code (CSharp):
    1. var request = new HTTPRequest(new Uri("http://httpbin.org/redirect/3"), (req, resp) =>
    2. {
    3.     Debug.Log(resp.DataAsText);
    4.     Debug.Log(resp.GetFirstHeaderValue("Location"));
    5. });
    6.  
    7. request.MaxRedirects = 6;
    8. request.Send();
    If you set this to 0, you will disable all redirects.
     
  44. makeupsometthinglater

    makeupsometthinglater

    Joined:
    Jan 25, 2015
    Posts:
    2
    Thank you! It worked perfectly.
     
  45. sonluong1987

    sonluong1987

    Joined:
    May 10, 2014
    Posts:
    8
    Hi BestHTTP,

    Thank you for your great asset, it's saved me a lot of time! I've got a question though, do you guys support IL2CPP yet? I've exported my game to iOS using il2cpp but my requests aren't working. There is no response or error to be seen. Is this related to IL2CPP code stripping and how can I get around this?

    Thank you in advance!
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    Made some improvements in the latest update(and reported two bugs in IL2CPP to Unity), but the main problem is that the Socket class is broken in IL2CPP now. The good new is that they are working hard to bring it alive.
    After it's done, i will test the plugin further and will fix(and/or bugreport) any incompatibilities that i found.
     
  47. sonluong1987

    sonluong1987

    Joined:
    May 10, 2014
    Posts:
    8
    Thank you for your quick reply. I'm just using regular Get/Post requests with BestHTTP in my project though, I tried creating a new project with a simple test script:
    Code (CSharp):
    1.         HTTPRequest request = new HTTPRequest(new System.Uri("http://www.google.com"),(req, res) => {
    2.             if (res != null) {
    3.                 Debug.Log(res.DataAsText);
    4.             }
    5.             else {
    6.                 Debug.Log("...No response?");
    7.             }
    8.         });
    9.         request.DisableCache = true;
    10.         request.Send();
    But I don't get anything back in iOS, not even the "No response" text ( it works well in the editor ). Do I have to do something else in order for it to work?
     
  48. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,665
    No, you can't. Targeting IL2CPP will work again only when they release a patch fixing Sockets. (The socket now can't connect to the server, so even very basic requests can't be made...)
     
  49. sonluong1987

    sonluong1987

    Joined:
    May 10, 2014
    Posts:
    8
    I see... so everything in BestHTTP depends on Sockets doesn't it? Thank you for your support, hope they get it out quickly :(
     
  50. Xemenas

    Xemenas

    Joined:
    Sep 10, 2012
    Posts:
    28
    Hi,

    I'm using BestHTTP to perform calls with several other REST APIs and I'm trying to debug one of the HTTPRequest urls. I've tried looking at the documentation, but haven't been able to find anything, is there a simple way to output the completely formed url? (i.e what it would look like when sent)

    Thank you!