Search Unity

Best HTTP Released

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

  1. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @yaukey

    Just tried with a fresh project, downloaded the latest plugin from the store and built a WebGL build and it's working as expected!

    Can you add more context to this issue? What version of the plugin, how/when you receive this error?
    upload_2017-6-28_16-59-50.png
     
  2. Yaukey

    Yaukey

    Joined:
    Feb 25, 2013
    Posts:
    8
    Hi~ I found it is unity's bug, because i always build with options "Development Build" and "Use pre-built Engine" both enabled, after tried with different option, I found that "Use pre-built Engine" is the trouble maker. Just disable it everything is ok! Thank you!
     
  3. GDevTeam

    GDevTeam

    Joined:
    Feb 14, 2014
    Posts:
    22
    Any known issues using with Unity 2017 RC1 (Release Candidate 1)? Or are we good to go?
     
  4. Michael_Squiers

    Michael_Squiers

    Joined:
    Nov 6, 2014
    Posts:
    29
    Hi, I recently bought your plugin and am pleased with the results so far. I am using AWS and have been able to get GET working easy enough, but I am having a hard time with POST. I found an example form that works well to post to an S3 bucket.

    Code (CSharp):
    1. <html>
    2.   <head>
    3.     <title>S3 POST Form</title>
    4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    5.   </head>
    6.  
    7.   <body>
    8.     <form action="https://s3.amazonaws.com/mybucket.testimage" method="post" enctype="multipart/form-data">
    9.       <input type="hidden" name="key" value="uploads/${filename}">
    10.  
    11.       <!-- Include any additional input fields here -->
    12.  
    13.       File to upload to S3:
    14.       <input name="file" type="file">
    15.       <br>
    16.       <input type="submit" value="Upload File to S3">
    17.     </form>
    18.   </body>
    19. </html>
    The code above works well in HTML, and I am able to post to the S3 bucket using the HTML form.

    Code (CSharp):
    1. new HTTPRequest(new Uri("https://s3.amazonaws.com/mybucket.testimage"), HTTPMethods.Post, (request, responseObj) =>{
    2.             request.SetHeader("Content-Type", "text/html; charset=UTF-8");
    3.             request.AddField("key", "Image/");
    4.             request.AddBinaryData("file", MyTexture.EncodeToJPG(30), "image.jpg");
    5.            
    6.             if(responseObj.IsSuccess == true){
    7.                 Debug.Log("Success");
    8.             }
    9.             else{
    10.                 Debug.Log("Failed");
    11.             }
    12.                 }).Send();
    Ive tried to convert the simple form into the BestHTTP Schema, and I havent had a successful response yet. Im using the C# lamba, I just don't know what the difference between the file in the html version vs the c# version. Any help would be greatly appreciated, Thanks
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @UnityDesingingDev

    v1.10.0 contains changes to work well with 2017.1, but if you already on the latest version of the plugin it should work just fine.
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @therockswell

    The problem is, that lambda function is called when the request completed. So you are setting the request's headers and form data after the request has been sent and the response downloaded.

    It should be something like this:
    Code (CSharp):
    1. var req = new HTTPRequest(new Uri("https://s3.amazonaws.com/mybucket.testimage"), HTTPMethods.Post, (request, responseObj) => {
    2.   if (responseObj.IsSuccess == true)
    3.   {
    4.     Debug.Log("Success");
    5.   }
    6.   else
    7.   {
    8.     Debug.Log("Failed");
    9.   }
    10. });
    11. req.SetHeader("Content-Type", "text/html; charset=UTF-8");
    12. req.AddField("key", "Image/");
    13. req.AddBinaryData("file", MyTexture.EncodeToJPG(30), "image.jpg");
    14. req.Send();
     
  7. melefans

    melefans

    Joined:
    Aug 1, 2016
    Posts:
    36
    Hi @BestHTTP
    In ios , android, unityeditor (window / mac) mode, I have a packet data size is 2000byte, sent data to server can success, but I export UWP project ( I2CPP && .NET2.0 ) ,then start the program with visual studio,with wireshark capturing Packet, found a lot of retry reset transmission 1460, Packet length : 1514 bytes, server can't receive this data. May be related to MTU.

    protocol: wws
    I have upgraded to the latest version。
    I would like to confirm that besthttp may cause this problem?
    Is it possible to change the TcpClient class? do you have any suggestions here?
     
    Last edited: Jul 1, 2017
  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @melefans

    I'm sorry, but I couldn't reproduce it. Scripting Backend: IL2CPP, Api Compatibility Level: .NET 2.0. Sent a text message (16260 bytes) to the websocket echo server through wss://, and it was sent out and the client could receive it back too.
     
  9. Steffen-ttc

    Steffen-ttc

    Joined:
    May 27, 2017
    Posts:
    3
    Thanks @BestHTTP,

    your solution helped a lot.
     
  10. Michael_Squiers

    Michael_Squiers

    Joined:
    Nov 6, 2014
    Posts:
    29
    Thank You, This worked. Now I am trying to use a PUT Method instead. In the AWS Docs there is a request header

    PUT /my-image.jpg HTTP/1.1
    Host: myBucket.s3.amazonaws.com
    Date: Wed, 12 Oct 2009 17:50:00 GMT
    Content-Type: text/plain
    Content-Length: 11434
    x-amz-meta-author: Janet

    How would I format a request header to work with BestHTTP
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @therockswell

    It should be something like this, with some room for improvements:
    Code (CSharp):
    1. Uri uri = new Uri("https://mybucket.s3.amazonaws.com/my-image.jpg");
    2. HTTPRequest request = new HTTPRequest(uri, HTTPMethods.Put, (req, resp) =>
    3. {
    4.     // TODO
    5. });
    6.  
    7. request.SetHeader("Date", DateTime.UtcNow.ToString()); // This might be not in the correct, expected format!
    8. request.SetHeader("Content-Type", "text/plain");
    9. request.SetHeader("x-amz-meta-author", "janet");
    10.  
    11. // Content-Length will be calculated and set by the plugin
    12.  
    13. request.RawData = MyTexture.EncodeToJPG(30);
    14.  
    15. request.Send();
    But, i'm not sure why you have to set the Content-Type to "text/plain" when you send a binary image.
     
    Last edited: Jul 5, 2017
  12. reddy36996

    reddy36996

    Joined:
    Jan 10, 2016
    Posts:
    19
    I also got the same issue recently :
    Internal TLS error, this could be an attack at Org.BouncyCastle.Crypto.Tls.TlsProtocol.FailWithError
    In my case, issue was i was accesing server hosted locally that is https://localhost:portnum.
    After changing it to http://localhost:portnum, it worked. Trick was to use http instead of https in uri
     
  13. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
  14. bmorgan-ksg

    bmorgan-ksg

    Joined:
    Dec 13, 2016
    Posts:
    3
    Hello, I am currently using the Websocket classes on a multi platform project. On mobile, when the application is sent to the background and remains there for an extended period of time, the next time it is brought to the foreground the socket connection has been closed.

    When this occurs, I remove all listeners from the existing socket, set it to null, instantiate a new socket and call the open function on it. This workflow produces the error below immediately after the open call is made. Once the error is thrown, the newly created socket functions as I would expect. Any insight on what could be causing this or how I could go about resolving it? Our server is using the websocket library that comes bundled with the Play Framework. Thank you for your time.

    Err [WebSocket]: Request Finished with Error! Exception: TCP Stream closed unexpectedly by the remote server at BestHTTP.WebSocket.Frames.WebSocketFrameReader.ReadByte (System.IO.Stream stream) [0x0000f] in C:\_work\ksg-casino\Deployment\trunk\Game\Assets\Plugins\BestHTTP\WebSocket\Frames\WebSocketFrameReader.cs:140
    at BestHTTP.WebSocket.Frames.WebSocketFrameReader.Read (System.IO.Stream stream) [0x00004] in C:\_work\ksg-casino\Deployment\trunk\Game\Assets\Plugins\BestHTTP\WebSocket\Frames\WebSocketFrameReader.cs:65
    at BestHTTP.WebSocket.WebSocketResponse.ReceiveThreadFunc (System.Object param) [0x00016] in C:\_work\ksg-casino\Deployment\trunk\Game\Assets\Plugins\BestHTTP\WebSocket\WebSocketResponse.cs:333
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Error(String, String) (at Assets/Plugins/BestHTTP/Logger/DefaultLogger.cs:76)
    BestHTTP.WebSocket.WebSocket:OnInternalRequestCallback(HTTPRequest, HTTPResponse) (at Assets/Plugins/BestHTTP/WebSocket/WebSocket.cs:322)
    BestHTTP.HTTPRequest:CallCallback() (at Assets/Plugins/BestHTTP/HTTPRequest.cs:1240)
    BestHTTP.ConnectionBase:HandleCallback() (at Assets/Plugins/BestHTTP/Connections/ConnectionBase.cs:171)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Plugins/BestHTTP/HTTPManager.cs:602)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Plugins/BestHTTP/HTTPUpdateDelegator.cs:166)
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @rattlesnake

    I think it should be something like this:
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4.  
    5. using BestHTTP;
    6.  
    7. [RequireComponent(typeof(UnityEngine.UI.Image))]
    8. public sealed class ImageDownloader : MonoBehaviour
    9. {
    10.     const int LoadTextureAtDefaultValue = 512 * 1024;
    11.  
    12.     public string DownloadURL = "http://www.doctorsintraining.com/wp-content/uploads/2013/05/Woman-taking-test.jpg";
    13.  
    14.     UnityEngine.UI.Image _img;
    15.     HTTPRequest request;
    16.  
    17.     int loadTextureAt = -1;
    18.     private Texture2D texture;
    19.  
    20.     System.IO.MemoryStream downloadedContent = new System.IO.MemoryStream();
    21.  
    22.     void Start()
    23.     {
    24.         BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.Warning;
    25.  
    26.         _img = GetComponent<UnityEngine.UI.Image>();
    27.     }
    28.  
    29.     private void OnGUI()
    30.     {
    31.         if (request == null && GUILayout.Button("Start"))
    32.             StartDownload();
    33.     }
    34.  
    35.     private void StartDownload()
    36.     {
    37.         downloadedContent.SetLength(0);
    38.         loadTextureAt = -1;
    39.         texture = new Texture2D(2, 2);
    40.  
    41.         request = new HTTPRequest(new Uri(DownloadURL), DownloadUpdate);
    42.         request.UseStreaming = true;
    43.         request.StreamFragmentSize = LoadTextureAtDefaultValue;
    44.         request.DisableCache = true;
    45.         request.Send();
    46.     }
    47.  
    48.     private void DownloadUpdate(HTTPRequest req, HTTPResponse resp)
    49.     {
    50.         switch (req.State)
    51.         {
    52.             case HTTPRequestStates.Processing:
    53.                 if (loadTextureAt == -1)
    54.                 {
    55.                     string value = resp.GetFirstHeaderValue("content-length");
    56.                     if (!string.IsNullOrEmpty(value))
    57.                     {
    58.                         int contentLength;
    59.                         if (int.TryParse(value, out contentLength))
    60.                             loadTextureAt = (int)(contentLength * 0.1f);
    61.                         else
    62.                             loadTextureAt = LoadTextureAtDefaultValue;
    63.                     }
    64.                     else
    65.                         loadTextureAt = LoadTextureAtDefaultValue;
    66.  
    67.                     Debug.Log("<color=blue>loadTextureAt set to " + loadTextureAt.ToString() + "</color>");
    68.                 }
    69.  
    70.                 ProcessFragments(resp.GetStreamedFragments());
    71.                 break;
    72.  
    73.             case HTTPRequestStates.Finished:
    74.                 // Process any remaining fragments
    75.                 ProcessFragments(resp.GetStreamedFragments());
    76.  
    77.                 // Completely finished?
    78.                 if (resp.IsStreamingFinished)
    79.                 {
    80.                     Debug.Log("<color=green>Load Large texture</color>");
    81.  
    82.                     // Load the final, large texture
    83.                     LoadContentToTexture();
    84.  
    85.                     request = null;
    86.                 }
    87.                 break;
    88.  
    89.             default:
    90.                 Debug.LogError("<color=red>Download failed: " + req.State.ToString() + "</color>", this);
    91.                 break;
    92.         }
    93.     }
    94.  
    95.     void ProcessFragments(List<byte[]> fragments)
    96.     {
    97.         if (fragments == null || fragments.Count == 0)
    98.             return;
    99.  
    100.         for (int i = 0; i < fragments.Count; ++i)
    101.         {
    102.             byte[] fragment = fragments[i];
    103.  
    104.             downloadedContent.Write(fragment, 0, fragment.Length);
    105.         }
    106.  
    107.         if (loadTextureAt != -1 && downloadedContent.Length >= loadTextureAt && _img.sprite == null)
    108.         {
    109.             Debug.Log("<color=yellow>Preload texture</color>");
    110.  
    111.             LoadContentToTexture();
    112.         }
    113.     }
    114.  
    115.     void LoadContentToTexture()
    116.     {
    117.         texture.LoadImage(downloadedContent.GetBuffer());
    118.         _img.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1f);
    119.     }
    120. }
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
  17. rattlesnake

    rattlesnake

    Joined:
    Jul 18, 2013
    Posts:
    138
    Perfect thank you :)

    Edit : PS sorry I know it's not HTTP-PRO related, but do you know a way to replace the grey color of the loading image by 100% transparency ?
     
    Last edited: Jul 10, 2017
  18. bmorgan-ksg

    bmorgan-ksg

    Joined:
    Dec 13, 2016
    Posts:
    3
    @BestHTTP

    Thank you for looking into this. Please let me know if I can provide anything else.
     
  19. Otaki

    Otaki

    Joined:
    Dec 30, 2015
    Posts:
    4
    @BestHTTP I am hoping I'm missing something simple, but I am unable to successfully connect to a node.js server that is using express and socket.io -- using Best HTTP - Pro

    I have included the very simple main.js test code, and the very simple TestBestHTTPSocketIO.cs code below... please help :)

    I am on Windows10 and Unity3d v5.6.2p2 Personal
    I see the connection attempt on the server, and the node.js console outputs: "USER CONNECTING..." but times out, and tries 3 times.

    Unity3d Error Message:
    Ex [PollingTransport]: ParseResponse - Message: 1: Array index is out of range. at BestHTTP.SocketIO.Transports.PollingTransport.ParseResponse (BestHTTP.HTTPResponse resp) [0x00054] in D:\MyProject\Assets\Best HTTP (Pro)\BestHTTP\SocketIO\Transports\PollingTransport.cs:354 StackTrace: at BestHTTP.SocketIO.Transports.PollingTransport.ParseResponse (BestHTTP.HTTPResponse resp) [0x00054] in D:\MyProject\Assets\Best HTTP (Pro)\BestHTTP\SocketIO\Transports\PollingTransport.cs:354
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Exception(String, String, Exception) (at Assets/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:111)
    BestHTTP.SocketIO.Transports.PollingTransport:parseResponse(HTTPResponse) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Transports/PollingTransport.cs:407)
    BestHTTP.SocketIO.Transports.PollingTransport:OnRequestFinished(HTTPRequest, HTTPResponse) (at Assets/Best HTTP (Pro)/BestHTTP/SocketIO/Transports/PollingTransport.cs:187)
    BestHTTP.HTTPRequest:CallCallback() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:1251)
    BestHTTP.ConnectionBase:HandleCallback() (at Assets/Best HTTP (Pro)/BestHTTP/Connections/ConnectionBase.cs:171)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:593)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:163)

    main.js
    Code (JavaScript):
    1. var express = require('express');
    2. var app = express();
    3. var server = require('http').createServer(app);
    4. var io = require('socket.io').listen(server);
    5. app.set('port', process.env.PORT || 3000 );
    6.  
    7. io.on("connection", function(socket){console.log("----------- USER CONNECTING... ------------");socket.emit("USER_CONNECTED", "Success");});
    8. server.listen(app.get('port'), function(){console.log("----------- SERVER IS RUNNING ------------");});
    TestBestHTTPSocketIO.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using BestHTTP.SocketIO;
    4.  
    5. public class TestBestHTTPSocketIO : MonoBehaviour
    6. {
    7.     public SocketManager socketManager;
    8.     void Start()
    9.     {
    10.         TimeSpan miliSecForReconnect = TimeSpan.FromMilliseconds(1000);
    11.         SocketOptions options = new SocketOptions();
    12.         options.ReconnectionAttempts = 3;
    13.         options.AutoConnect = false;
    14.         options.ReconnectionDelay = miliSecForReconnect;
    15.  
    16.         socketManager = new SocketManager(new Uri("http://127.0.0.1:3000/socket.io/"), options);
    17.  
    18.         socketManager.Socket.On("USER_CONNECTED", OnUserConnected);
    19.         socketManager.Open();
    20.     }
    21.     private void OnUserConnected(Socket socket, Packet packet, params object[] args)
    22.     {
    23.         Debug.Log("Message from server is: " + args[0].ToString() + " OnUserConnected");
    24.     }
    25. }
     
  20. Otaki

    Otaki

    Joined:
    Dec 30, 2015
    Posts:
    4
    @BestHTTP can I also get a link to this patch? thanks!
     
  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @Otaki

    Sent a link in a private message.
     
    Otaki likes this.
  22. Otaki

    Otaki

    Joined:
    Dec 30, 2015
    Posts:
    4
    Working now, thanks!~
     
  23. blanksas

    blanksas

    Joined:
    Jul 17, 2017
    Posts:
    1
    hey @BestHTTP I am running Best HTTP Basic and I have the same issue than @Otaki - Can you also send a patch in a private message ? Please :oops:
    Thanks a lot guys,

    Alexis
     
  24. Tr3gan

    Tr3gan

    Joined:
    Dec 13, 2016
    Posts:
    11
    We're using BestHTTP, and I'd like to show a countdown to a timeout to users (both connection & request upload/download timeout). It would be awesome if you could add 1 event to requests: OnConnected, which is called when a request finds an available open connection or when a new connection for that request was established successfully. This way, I know which countdown I have to show to the users (20 seconds while OnConnected was not sent, but if we did receive it, show the 60 seconds for request timeout)

    Sorry if this has been asked before. 37 pages is quite something to go through :p
     
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @Tr3gan

    Unfortunately there's no such event, sorry.
     
  26. chriser

    chriser

    Joined:
    Jan 14, 2015
    Posts:
    2
    We are using BestHTTP for mobile and had some tests with 100% packet loss and timeouts.
    We found out that the DNS resolving during Connect(string hostname, int port) has no timeout set, so it fails after 30 secs with a SocketException: no such host is known.

    To fix this, we just used BeginGetHostAddresses instead of GetHostAddresses (just like you already implemented it in Connect(IPEndPoint remoteEP))

    Code (CSharp):
    1.  
    2. public void Connect(string hostname, int port)
    3. {
    4.     System.Threading.ManualResetEvent mre = new System.Threading.ManualResetEvent(false);
    5.     IAsyncResult result = Dns.BeginGetHostAddresses(hostname, (res) => mre.Set(), null);
    6.     bool success = mre.WaitOne(ConnectTimeout);
    7.     if (success)
    8.     {
    9.         IPAddress[] addresses = Dns.EndGetHostAddresses(result);
    10.         Connect(addresses, port);
    11.     }
    12.     else
    13.     {
    14.         throw new TimeoutException("DNS resolve timed out!");
    15.     }
    16. }
    17.  
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @chriser

    Thanks, I will add it to the next release!
     
  28. invictvs1

    invictvs1

    Joined:
    Mar 7, 2014
    Posts:
    14
    hey @BestHTTP - quick question for you. I'm currently working on a port to a UWP app and getting some strange errors when using IL2CPP as a Scripting Backend. When I try to build I see errors like:

    Code (CSharp):
    1. The type 'List<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
    2.  
    The line points to the GetStreamedFragments() method. We also have an error on some dictionaries which point to us reading the response headers. Any idea what could be going on here? Thanks in advance, keep up the good work!
     
  29. Cromfeli

    Cromfeli

    Joined:
    Oct 30, 2014
    Posts:
    197
    EDIT: Will try latest version
     
    Last edited: Jul 28, 2017
  30. invictvs1

    invictvs1

    Joined:
    Mar 7, 2014
    Posts:
    14
    I was able to figure this out but now I'm getting some odd request exceptions:

    'Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFolder>.GetResults' on type 'System.__Il2CppComObject' failed.

    Any idea what this could mean? I'm on .NET 4.6 Compatibility & IL2CPP UWP.
     
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @Cromfeli

    Thanks for the report. v1.10.1 should be out soon, please try out with that too.
     
  32. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @invictvs1

    I'm sorry, but i couldn't reproduce it. I could create a fresh project, import the plugin into it and make an UWP build using IL2CPP. I compiled succesfully with both Stable and with the new Experimental 'Scripting Runtime'.
    I used Unity 2017.1.0f3.
     
  33. invictvs1

    invictvs1

    Joined:
    Mar 7, 2014
    Posts:
    14
    Hmm interesting, what about on 5.6.2p4? That's what I'm currently on. I had some issues with stripping on .NET 4.6 so I'm actually using a custom version of JSON.NET DLL but I don't believe that would affect the response I'm getting.
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @invictvs1

    Tried out with Unity 5.6.2f1, and it worked without any issues:
    upload_2017-7-28_13-56-41.png
    upload_2017-7-28_13-56-55.png
     
  35. invictvs1

    invictvs1

    Joined:
    Mar 7, 2014
    Posts:
    14
    Odd, thanks for trying that out. I'm going to see what happens with a new project, maybe there is some weird setting.

    EDIT:

    Are you using the source code or precompiled for IL2CPP?
     
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
  37. oddmax

    oddmax

    Joined:
    May 10, 2017
    Posts:
    1
    @BestHTTP Hello! Thank you for the great plug-in!
    We are using PRO version and, currently, we have an issue. In our crashlytics reports some users have this exception on their iPhone devices (only on iPhones):
    Code (CSharp):
    1. SocketException : The requested address is not valid in this context
    2.  
    3. Send (System.Net.Sockets.Socket)
    4. Write (System.Net.Sockets.NetworkStream)
    5. WriteRecord (Org.BouncyCastle.Crypto.Tls.RecordStream)
    6. SafeWriteRecord (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    7. RaiseAlert (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    8. FailWithError (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    9. HandleClose (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    10. Close (Org.BouncyCastle.Crypto.Tls.TlsStream)
    11. Abort (BestHTTP.HTTPConnection)
    12. OnUpdate (BestHTTP.HTTPManager)
    13. Write (System.Net.Sockets.NetworkStream)
    14. WriteRecord (Org.BouncyCastle.Crypto.Tls.RecordStream)
    15. SafeWriteRecord (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    16. RaiseAlert (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    17. FailWithError (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    18. HandleClose (Org.BouncyCastle.Crypto.Tls.TlsProtocol)
    19. Close (Org.BouncyCastle.Crypto.Tls.TlsStream)
    20. Abort (BestHTTP.HTTPConnection)
    21. OnUpdate (BestHTTP.HTTPManager)
    It would be great if you can point what can be an issue or give any idea where to look at. Thank you!
     
  38. AG_Dan

    AG_Dan

    Joined:
    Jul 31, 2017
    Posts:
    6
    I've discovered what seems to be a bug in the way BestHTTP handles redirects and response caching. We have an API on our server that responds with a redirect to a URL on our CDN. The URL that it redirects to changes periodically and we always want our clients to receive the latest redirect so the response should never be cached, but the content stored on the CDN is immutable and can be cached pretty much forever. Accordingly, the initial redirect response is a "302 Found" (not "301 Permanently Moved") with all the appropriate cache control headers set to indicate that it should not be cached, while the response from the CDN has cache control headers indicating that that response can be cached. With this setup, my expectation is that executing a GET request to the route on our server would always perform the initial request, receive the redirect response, and if the redirect URI is the same as the last time, then it should already have the response from the CDN in the cache and can return it immediately.

    Instead, what I am seeing happen is that the response from the CDN is being cached at the original URI, rather than at the redirected URI. Subsequent calls then just return that cached value, rather than hitting our server again to get the latest redirect URI. Unless I am completely mistaken about how this scenario should behave, this seems like a bug.

    NOTE: I have temporarily worked around this problem by commenting out the code in HTTPConnection.TryStoreInCache() that intentionally caches the result of a redirect at the source URI rather than the redirected URI (lines HTTPConnection.cs@765-767):

    Code (CSharp):
    1.                 // AG: Never cache the results of a redirect at the source Uri.
    2.                 //if(CurrentRequest.IsRedirected)
    3.                 //    HTTPCacheService.Store(CurrentRequest.Uri, CurrentRequest.MethodType, CurrentRequest.Response);
    4.                 //else
    5.                     HTTPCacheService.Store(CurrentRequest.CurrentUri, CurrentRequest.MethodType, CurrentRequest.Response);
     
  39. AG_Dan

    AG_Dan

    Joined:
    Jul 31, 2017
    Posts:
    6
    We are seeing a very similar issue on PlayStation. Here's a screenshot of the callstack: callstack.png
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @oddmax && @AG_Dan

    Thanks for these interesting stack traces, i will try to reproduce it.
    (My first guess though is that the server closes the connection.)
     
  41. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @AG_Dan

    Cache it for the original uri was intentional, I will think about this.
     
  42. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    78
    Is it possible to use this plugin to monitor (like every X seconds), whether application has an active internet connection efficiently?
     
  43. nemonet

    nemonet

    Joined:
    Aug 13, 2015
    Posts:
    1
    @BestHTTP hi, having exactly the same issue as @Otaki. All worked fine while working on local socket.io server but when i tried to test on a production server i get:

    Ex [PollingTransport]: ParseResponse - Message: 1: Array index is out of range. at BestHTTP.SocketIO.Transports.PollingTransport.ParseResponse

    And i can't connect. After some hours getting mad trying to figure out why is working on local and not working on production i discovered that problem is socket.io version. Seems current BEST HTTP is not compatible with socket.io 2.0 so now i got it working downgrading production socket.io version to 1.4.6 and now is working.
    Could i get the patch ?

    Thanks
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
  45. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @nemonet

    The latest version of the plugin just went live this week, you can update the plugin from the Asset Store now.
     
    Cromfeli likes this.
  46. Jochanan

    Jochanan

    Joined:
    Nov 9, 2016
    Posts:
    78
  47. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,410
    @Jochanan

    In this case you could treat every request State other than Finished as an internet-not-reachable event, but I wouldn't treat it as very reliable.
     
    Jochanan likes this.
  48. FatIgor

    FatIgor

    Joined:
    Sep 13, 2015
    Posts:
    29
    Hi.
    I've been using BestHTTP for a long time now, without any problems.
    However, since Friday, I've been having a weird problem.

    Is there a reason why a mobile data call would work much more quickly than one over wireless?

    My code runs fine on our production server, but has problems on our staging server.

    On the staging server my code is failing over wifi (95% of time, with the occasional one getting through) but succeeding over mobile data.(Not just me, testers as well, both android and ios.) Is there some sort of timing distinction between wifi and mobile data in the code?

    Our staging server (hosted on Azure) was dropped in quality on Friday which is when the problem started. I've tried upping my timeouts but it makes no difference. (Plus on mobile data it goes through pretty quickly anyway.)

    On mobile data a login call averages around 1.2 seconds from request.send to the callback
    On wifi the login call generally takes just over timeout time, and returns null.
    With the warning message
    "Failed to read status line! Retry is enabled, returning with false."


    [EDIT] Don't know why I did not try this,above was with development build on android and ios. Switching to release build, it works fine with wi-fi again.
     
    Last edited: Aug 8, 2017
  49. cong91

    cong91

    Joined:
    May 31, 2013
    Posts:
    5
    Hi !!!
    I have problems when receive surrogate character for example (⏬'☕) or China Character from server.

    When server response this character I have bug log in this

    Please help me. This bug absolutely dangerous with me :(.
    Sorry my bad english
     
  50. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    503
    hey there,

    Are there any tutorials using cURL code?
     
    Last edited: Aug 9, 2017
unityunity