Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. 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,653
    @note_nota

    As I see the original problem was this: "Failed to fix references for type LitJson.IJsonWrapper". You have a LitJson.dll somewhere, and the plugin also comes with LitJson too.
    Deleting the \Assets\Best HTTP (Pro)\Examples folder should fix this problem.
     
  2. note_nota

    note_nota

    Joined:
    Aug 9, 2016
    Posts:
    3
    Thanks your advice.
    But the "Examples" folder did not exist anymore.
    Could you have an another way?
     
  3. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @note_nota Are you receiving the very same error?
     
  4. note_nota

    note_nota

    Joined:
    Aug 9, 2016
    Posts:
    3
    The Answer of your question is "Yes".

    I check the commit log and try some examples. Then I reach a little thing.
    The LitJson.dll that is another of yours is in my project.
    Oh... I couldn't use your LitJson's method.
    So, I try the another way of using the json data. JsonUtility?

    Thanks of your kindness.
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @note_nota

    If you deleted the 'Examples' folder that contains my LitJson code and you are still receiving the very same error message, then the problem might be in the LitJson.dll, or somewhere else.
    The plugin itself (just checked out again) compile and run perfectly on windows 10.
     
  6. BlaceX

    BlaceX

    Joined:
    Oct 28, 2015
    Posts:
    7
    Hi

    When sending a POST request with form data the Mime type will be defined based on the length of the longest form value.

    If there is a value with length greater than 256 the Mime type will be Multipart, otherwise it will be url-encoded.

    Could you explain your decision for defining the Mime type based on a form value length and why the max length is 256 ?

    Thanks in advance
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @BlaceX

    To url-encode the data, it must go through the whole string and check every character and create a new encoded string. For large strings it can be a burden on CPU and on memory too. On the other hand, multipart encoding will send the data as-is, with much less overhead.

    I see the 256 length limit as a good balance between the two encoding.
    Users who has the Pro version can change this limit, or the plugin can be forced to stick with one encoding by setting the request's FormUsage property other then HTTPFormUsage.Automatic.
     
  8. BlaceX

    BlaceX

    Joined:
    Oct 28, 2015
    Posts:
    7
    Thanks for the reply

    I already figured out how to change it, I just wanted to understand why this limit was set before ignoring it.

    I just started using the plugin but it seems great. Miles better than the disappointing new UnityWebRequest. Keep up the good work.
     
  9. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    This is the error I'm receiving:
    Also, on the OnRequestFinished(HTTPRequest request, HTTPResponse response) method callback, the response parameter is coming in null. Do you know what might cause this?
     
    Last edited: Aug 16, 2016
  10. kenmgrimm

    kenmgrimm

    Joined:
    Nov 26, 2013
    Posts:
    34
    The docs mention that gzip compression is supported and appears to be on by default. I know that I can receive gzip'd content and my accepts-encoding includes gzip however when POSTing from BestHTTP I'm not seeing the contents of the POST body being compressed. I don't see anything in the docs regarding enabling POST data compression, is this something that I must enable?

    Here is my code:

    HTTPRequest request = new HTTPRequest(updateRoute, HTTPMethods.Post, OnUpdateRequestFinished);

    request.AddField("data", dataJsonStr);

    request.Send();



    And here is the Wireshark captured POST body:


    POST /paintings/32 HTTP/1.1

    Host: localhost:3000

    Accept-Encoding: gzip, identity

    Connection: Keep-Alive, TE

    TE: identity

    User-Agent: BestHTTP

    Content-Type: multipart/form-data; boundary="5DB5DB80"

    Content-Length: 5327



    --5DB5DB80

    Content-Disposition: form-data; name="painting"

    Content-Type: text/plain; charset="utf-8"

    Content-Length: 5183


    {"id":32,"latitude":2.0999999046325685," ...
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Ben-BearFish The plugin failed to write to the underlying NetworkStream. It's an error unrelated to the plugin, most probably the OS or the remote peer closed the TCP connection.
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @kenmgrimm
    The plugin will not compress outgoing data, the Accept-Encoding informs the server that the client can decompress data if the server send it so.

    I think no http client uses client side compression with Content-Encoding.
    You can compress the data manually and send it so, though.
     
  13. kenmgrimm

    kenmgrimm

    Joined:
    Nov 26, 2013
    Posts:
    34
    That makes sense, I suppose it wouldn't know whether the server supported it. This is mobile so I want to cut down on payload size. I'll take your advice and compress manually.
    Thanks
     
  14. janus007

    janus007

    Joined:
    Apr 12, 2016
    Posts:
    5
    Hi
    I'm using UnityWebrequest from another thread than main, I keep getting these:

    InternalBegin can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.


    I imagine that UnityWebRequest uses some annoying coupling to objects that needs to be in the same context. Anyway...
    Before I buy.... how does BestHttp react to be called from another thread?

    Well... I just bought it instead to test it :)

    ArgumentException: get_isDebugBuild can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    BestHTTP.Logger.DefaultLogger..ctor () (at Assets/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:28)
    BestHTTP.HTTPManager..cctor () (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:39)
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for BestHTTP.HTTPManager
    BestHTTP.HTTPRequest..ctor (System.Uri uri)
     
    Last edited: Aug 18, 2016
  15. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    It looks like we've noticed that we're experiencing an issue where after making web requests the BestHttp plugin is not releasing the bytes to the garbage collector. Is there a way for us to tell the BestHttp plugin to release all memory? Or something similar to that? This seems weird because we turned Caching off. We're using a WebPlayer build with the latest version of BestHTTP from the asset store.
     
  16. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @janus007

    You have to call the HTTPManager.Setup(); somewhere in your startup code in a Unity function (Start, Awake, etc). After this, you should be able to send requests in an another thread without any issue.
     
  17. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Ben-BearFish

    In WebPlayer builds caching is disabled by the plugin too, as it can't save the content. The downloaded bytes are referenced by the HTTPResponse object only. The HTTPRequest has a reference to this response object, but after the callback is called no reference is kept to the request to let the GC clean up.

    Even when caching is on the plugin doesn't keep the response in memory.
     
  18. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Could I ask you, when I download the bytes from the server, in our case a few hundred MB file, we noticed that the Unity Editor profiler does not seem to be able to see these bytes when we were debugging this. Might this be related to our issue that somehow the Mono GC is not detecting the bytes?
     
  19. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @BestHTTP I believe the issue is related to this issue here.

    They said when you allocate too large of a byte array, Unity's Mono Large Objects Heap does not free the memory again. Is there a way to have the BestHttp break the bytes array in the Response Data into chunks of smaller byte arrays, so that the memory can be released back to the system? This would help with downloading larger files from the server.
     
    Last edited: Aug 20, 2016
  20. Zeitcatcher

    Zeitcatcher

    Joined:
    Dec 11, 2012
    Posts:
    21
    I am having a problem with System.Uri objects unexpectedly converting to lower case in WebGL builds.

    I am sending HTTPRequest to an URL that includes mixed case token (as part of the URL), and while it works fine in the editor, when I launch it either locally or from the server as a WebGL build, I'm getting 401 Unauthorized errors from BestHTTP due to the URL (and the token) becoming lowercase.

    Using standard Unity WWW with the URL as a string instead of System.Uri works fine.

    I'm not sure if that's proper behavior for System.Uri on WebGL platform, but I'd very much appreciate some help in that matter. Like is there a workaround to use a string for URL in HTTPRequest instead of System.Uri? Or if that's a supposed Unity bug, please let me know, so that I can fill a bug report.

    I'm on Unity Pro 5.4.0f3 with Best HTTP (Pro Edition) 1.9.13

    Thanks.
     
  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Ben-BearFish

    The plugin doesn't use any tricks to keep the allocated memory unreleased. It uses 'new byte[..]' allocations, MemoryStreams and such.

    Large Object Heap will also release the allocated memory, but just less frequently. At least it should do so, and I think Unity would fix a bug like this.

    What I can think of is
    1. maybe somehow you are still keeping a reference to these byte arrays or theirs derivatives(string, texture2ds, etc made from the downloaded content)
    2. maybe mono releases the memory for future use for itself, but not for the OS?

    You can try out download streaming, it basically gives the download data in chunks.
    And/or, you can try out Unity's new experimental Memory Profiler.
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Zeitcatcher

    It was a bug in the plugin that i fixed now. I will send you a fixed package in a private message.
     
  23. DimPV

    DimPV

    Joined:
    Aug 22, 2016
    Posts:
    2
    I am new to Socket IO and I tried to connect to Socket.IO Chat sample myself before implementing a connection with my own server.


    I am using the code below:

    Code (CSharp):
    1. using UnityEngine;
    2. using BestHTTP.SocketIO;
    3. using System;
    4.  
    5. public class TestingChatIO : MonoBehaviour
    6. {
    7.     public string chatServerURL = "http://chat.socket.io/socket.io/";
    8.  
    9.     /// The Socket.IO manager instance.
    10.     private SocketManager Manager;
    11.  
    12.     // Use this for initialization
    13.     void Start()
    14.     {
    15.         // Change an option to show how it should be done
    16.         SocketOptions options = new SocketOptions();
    17.         options.AutoConnect = false;
    18.  
    19.         // Create the Socket.IO manager
    20.         Manager = new SocketManager(new Uri(chatServerURL), options);
    21.  
    22.         Manager.Socket.On("connect", OnConnect);
    23.  
    24.         Manager.Socket.On("connecting", OnConnecting);
    25.  
    26.         // Set up custom chat events
    27.         Manager.Socket.On("login", OnLogin);
    28.  
    29.         // Add error handler, so we can display it
    30.         Manager.Socket.On(SocketIOEventTypes.Error, OnError);
    31.  
    32.         // The argument will be an Error object.
    33.         //Manager.Socket.On(SocketIOEventTypes.Error, (socket, packet, args) => Debug.LogError(string.Format("Error: {0}", args[0].ToString())));
    34.  
    35.         // We set SocketOptions' AutoConnect to false, so we have to call it manually.
    36.         Manager.Open();
    37.     }
    38.  
    39.     private void OnConnecting(Socket socket, Packet packet, params object[] args)
    40.     {
    41.         Debug.Log("Starting connecting");
    42.     }
    43.  
    44.     private void OnConnect(Socket socket, Packet packet, params object[] args)
    45.     {
    46.         Debug.Log("Connect the namespace is open");
    47.     }
    48.  
    49.     private void OnLogin(Socket socket, Packet packet, params object[] args)
    50.     {
    51.         Debug.Log("Welcome to Socket.IO Chat — \n");
    52.     }
    53.  
    54.     /// <summary>
    55.     /// Called on local or remote error.
    56.     /// </summary>
    57.     private void OnError(Socket socket, Packet packet, params object[] args)
    58.     {
    59.         Debug.Log("--ERROR --\n");
    60.     }
    61.  
    62.     void OnDestroy()
    63.     {
    64.         // Leaving this sample, close the socket
    65.         Manager.Close();
    66.     }
    67. }

    From the Console after the “Starting Connection” I get an “--ERROR--” message and then Ex [PollingTransport]: ParseResponse - Message: 1: Array index is out of range.


    I don’t know what is the cause of the error. Keep in mind that the Packages Samples work as intended.
     
  24. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Normally, regarding the Large Object Heap, I would say Unity would handle a bug like that, but they can't because of the Mono Garbage Collector they are using underneath Unity 5.3. In the article I read, if a byte array is over a certain size it is like #2 that you described, that it does not release the memory back to the OS, which causes the application to continue to expand and eventually run out of memory. I know the references we have for the byte arrays are released, but we have not tried the streaming API you wrote. We'll try the streaming API and get back to you with the results. Thanks for the suggestion.
     
  25. phil-harvey

    phil-harvey

    Joined:
    Aug 27, 2014
    Posts:
    74
    I notice in TCPClient the start up code is

    public TcpClient()
    {
    Init(AddressFamily.InterNetwork);
    client.Bind(new IPEndPoint(IPAddress.Any, 0));

    We are using BestHttp and apple rejected us because we did not support IPv6. I see in the class below the check for addressFamily. In HTTPConnection it is just calling

    if (Client == null)
    Client = new TcpClient();

    can I just change this to

    if (Client == null)
    Client = new TcpClient(AddressFamily.InterNetworkV6);

    Thanks

    Phil
     
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @DimPV

    Most probably server issues. Tried out yesterday night, and while first it printed out the error string, when i wanted to debug it started working. And today I receive '502 Bad Gateway's.
    Anyway, in the error callback will receive an Error object that you can use to print out more details what went wrong:
    Code (CSharp):
    1. private void OnError(Socket socket, Packet packet, params object[] args)
    2. {
    3.     Debug.Log(string.Format("--ERROR: {0} --\n", args[0]));
    4. }
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @phil-harvey

    The main code is in the Connect function (starting around line 408): this function will receive an array of IPAddress and will try to connect to them. An IPAddress struct can hold ipv4 or ipv6 addresses and the function will handle both correctly.
    There are two thing that you have to aware of:
    1. You must not use any IP literals like "1.2.3.4", instead you have to use host names like "myserver.com"
    2. You have to use a Unity version that has proper IPv6 support.
    You can read more about this in more detail in this blog post: Unity And IPv6 Support.
     
  28. DimPV

    DimPV

    Joined:
    Aug 22, 2016
    Posts:
    2
    Thank you for the response!

    I tested my code using the chat server URL and also get 502 Bad Gateway’s (I no longer get “Ex [PollingTransport]: ParseResponse - Message: 1: Array index is out of range”)

    Now I tried to connect with my server, that is implemented using Netty-socketio (https://github.com/mrniko/netty-socketio/) version 1.7.11.

    The configuration of the server is pretty standard except in com.corundumstudio.socketio.Configuration when AllowCustomRequests = false then in Unity Console I get a “--Error Code: Internal Message “Can’t parse” as a hex number!”

    Now if in com.corundumstudio.socketio.Configuration the AllowCustomRequests = true then the server raises a NullPointerException on server ProtocolHandler

    Log example:

    java.lang.NullPointerException: null

    at com.corundumstudio.socketio.transport.WebSocketTransport.channelRead(WebSocketTransport.java:116)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:326)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)


    So I can’t connect using BestHTTP Pro. The strange thing is that using the Socket.IO for Unity (https://www.assetstore.unity3d.com/en/#!/content/21721) I can normally connect to the server and get the init event.
     
  29. xpxilom

    xpxilom

    Joined:
    Aug 28, 2014
    Posts:
    30
    I get error when I try to load this image

    Code (CSharp):
    1.     public void Cargar_Foto_De_Perfil()
    2.     {
    3.         string UI1 = "http://graph.facebook.com/100009154388931/picture?type=large&redirect=false&width=480&height=400";
    4.  
    5.  
    6.         Uri uri = new Uri(UI1);
    7.  
    8.         HTTPRequest request2 = new HTTPRequest(uri, HTTPMethods.Get, (req, resp) =>
    9.             {              
    10.                 string St = resp.DataAsText;
    11.                 int pFrom = St.IndexOf("\"url\":\"") + "\"url\":\"".Length;
    12.                 int pTo = St.LastIndexOf("\",");
    13.                 String result = St.Substring(pFrom, pTo - pFrom);
    14.                 result = result.Replace("\\", "");
    15.                 Cargar_Foto_De_Perfil2(result);
    16.             });
    17.         request2.Send();
    18.     }
    19.  
    20.  
    21.  
    22.   public void Cargar_Foto_De_Perfil2(string perfil)
    23.     {
    24.         HTTPRequest request = new HTTPRequest(new Uri(perfil), HTTPMethods.Get, (req, resp) =>
    25.  
    26.             {
    27.                 var tex = new Texture2D(0, 0);
    28.                 tex.LoadImage(resp.Data); //Error here
    29.              
    30.                 FOTO_DE_PERFILE.GetComponent<Image>().overrideSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
    31.                  
    32.             });
    33.         request.Send();
    34.  
    35.         m_Thread = new System.Threading.Thread(Cargar_Grupos);
    36.         m_Thread.Start();
    37.  
    38.     }
    I worked before, and updates the plugin does not work
     
  30. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    We noticed issues in our Retrying of a GET request, and were wondering do we need to put in a time delay before retrying the request, or is sending the Retry Request the way you said in your example okay?
     
    Last edited: Aug 25, 2016
  31. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @DimPV

    Unfortunately I'm not very familiar with the java world and wasn't able to found a quick way to test it out myself.
    So it would be very helpful if you would be able to capture communication between the client and the server.
    1.) You can inform the plugin to use a proxy by setting the HTTPManager's Proxy property:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Proxy = new BestHTTP.HTTPProxy(new Uri("http://localhost:8888"), null, true);
    2.) Using Charles you can export the session through the "File/Export Session..." menu.

    You can send the captured session to my email address (besthttp@gmail.com).
     
  32. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Am i reading the asset store correctly when i assume that IL2CPP and BestHTTP Pro only works for iOS and not Android?
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Enzign
    Last time I checked il2cpp was in beta for Android, but it worked without any issue. It also works using il2cpp on Windows Store builds, so it should work on Android too.
     
  34. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Ok, ok. Thank you for the quick reply. IL2CPP isn't beta anymore for Android since Unity 5.4. But great that it should be working. My websocket requests aren't working, but then it probably has nothing to do with BestHTTP. I'll do some more testing, but then i know it should work.
     
  35. xpxilom

    xpxilom

    Joined:
    Aug 28, 2014
    Posts:
    30
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @xpxilom

    Using you code was able to download the picture without any issue. As a best practice I would recommend to check the request state:
    Code (CSharp):
    1. public void Cargar_Foto_De_Perfil()
    2. {
    3.     string UI1 = "http://graph.facebook.com/100009154388931/picture?type=large&redirect=false&width=480&height=400";
    4.  
    5.  
    6.     Uri uri = new Uri(UI1);
    7.  
    8.     HTTPRequest request2 = new HTTPRequest(uri, HTTPMethods.Get, (req, resp) =>
    9.     {
    10.         switch (req.State)
    11.         {
    12.             // The request finished without any problem.
    13.             case HTTPRequestStates.Finished:
    14.                 if (resp.IsSuccess)
    15.                 {
    16.                     Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    17.  
    18.                     string St = resp.DataAsText;
    19.                     int pFrom = St.IndexOf("\"url\":\"") + "\"url\":\"".Length;
    20.                     int pTo = St.LastIndexOf("\",");
    21.                     String result = St.Substring(pFrom, pTo - pFrom);
    22.                     result = result.Replace("\\", "");
    23.                     Cargar_Foto_De_Perfil2(result);
    24.                 }
    25.                 else // Internal server error?
    26.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    27.                                                     resp.StatusCode,
    28.                                                     resp.Message,
    29.                                                     resp.DataAsText));
    30.                 break;
    31.  
    32.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    33.             case HTTPRequestStates.Error:
    34.                 Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    35.                 break;
    36.  
    37.             // The request aborted, initiated by the user.
    38.             case HTTPRequestStates.Aborted:
    39.                 Debug.LogWarning("Request Aborted!");
    40.                 break;
    41.  
    42.             // Connecting to the server is timed out.
    43.             case HTTPRequestStates.ConnectionTimedOut:
    44.                 Debug.LogError("Connection Timed Out!");
    45.                 break;
    46.  
    47.             // The request didn't finished in the given time.
    48.             case HTTPRequestStates.TimedOut:
    49.                 Debug.LogError("Processing the request Timed Out!");
    50.                 break;
    51.         }
    52.     });
    53.     request2.Send();
    54. }
    55.  
    56.  
    57. public void Cargar_Foto_De_Perfil2(string perfil)
    58. {
    59.     HTTPRequest request = new HTTPRequest(new Uri(perfil), HTTPMethods.Get, (req, resp) =>
    60.     {
    61.         switch (req.State)
    62.         {
    63.             // The request finished without any problem.
    64.             case HTTPRequestStates.Finished:
    65.                 if (resp.IsSuccess)
    66.                 {
    67.                     var tex = new Texture2D(0, 0);
    68.                     tex.LoadImage(resp.Data); //Error here
    69.  
    70.                     FOTO_DE_PERFILE.GetComponent<Image>().overrideSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
    71.                 }
    72.                 else // Internal server error?
    73.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    74.                                                     resp.StatusCode,
    75.                                                     resp.Message,
    76.                                                     resp.DataAsText));
    77.                 break;
    78.  
    79.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    80.             case HTTPRequestStates.Error:
    81.                 Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    82.                 break;
    83.  
    84.             // The request aborted, initiated by the user.
    85.             case HTTPRequestStates.Aborted:
    86.                 Debug.LogWarning("Request Aborted!");
    87.                 break;
    88.  
    89.             // Connecting to the server is timed out.
    90.             case HTTPRequestStates.ConnectionTimedOut:
    91.                 Debug.LogError("Connection Timed Out!");
    92.                 break;
    93.  
    94.             // The request didn't finished in the given time.
    95.             case HTTPRequestStates.TimedOut:
    96.                 Debug.LogError("Processing the request Timed Out!");
    97.                 break;
    98.         }
    99.     });
    100.     request.Send();
    101.  
    102.     m_Thread = new System.Threading.Thread(Cargar_Grupos);
    103.     m_Thread.Start();
    104. }
     
  37. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @Ben-BearFish It should work as it is in my example. What issues are you experienced?
     
  38. xpxilom

    xpxilom

    Joined:
    Aug 28, 2014
    Posts:
    30
    Said this:
    Request Finished with Error! Internal TLS error, this could be an attack
    at Org.BouncyCastle.Crypto.Tls.TlsProtocol.FailWithError (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause) [0x0004a] in E:\Users\Xpxilo\Documents\Auto Publocador\Assets\Best HTTP (Pro)\BestHTTP\SecureProtocol\crypto\tls\TlsProtocol.cs:819

    @BestHTTP
     
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @xpxilom Hmm, that strange.
    You can try to disable the alternate ssl handler:
    Code (CSharp):
    1. public void Cargar_Foto_De_Perfil()
    2. {
    3.     string UI1 = "http://graph.facebook.com/100009154388931/picture?type=large&redirect=false&width=480&height=400";
    4.  
    5.  
    6.     Uri uri = new Uri(UI1);
    7.  
    8.     HTTPRequest request2 = new HTTPRequest(uri, HTTPMethods.Get, (req, resp) =>
    9.     {
    10.         switch (req.State)
    11.         {
    12.             // The request finished without any problem.
    13.             case HTTPRequestStates.Finished:
    14.                 if (resp.IsSuccess)
    15.                 {
    16.                     Debug.Log("Request Finished Successfully! Response: " + resp.DataAsText);
    17.  
    18.                     string St = resp.DataAsText;
    19.                     int pFrom = St.IndexOf("\"url\":\"") + "\"url\":\"".Length;
    20.                     int pTo = St.LastIndexOf("\",");
    21.                     String result = St.Substring(pFrom, pTo - pFrom);
    22.                     result = result.Replace("\\", "");
    23.                     Cargar_Foto_De_Perfil2(result);
    24.                 }
    25.                 else // Internal server error?
    26.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    27.                                                     resp.StatusCode,
    28.                                                     resp.Message,
    29.                                                     resp.DataAsText));
    30.                 break;
    31.  
    32.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    33.             case HTTPRequestStates.Error:
    34.                 Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    35.                 break;
    36.  
    37.             // The request aborted, initiated by the user.
    38.             case HTTPRequestStates.Aborted:
    39.                 Debug.LogWarning("Request Aborted!");
    40.                 break;
    41.  
    42.             // Connecting to the server is timed out.
    43.             case HTTPRequestStates.ConnectionTimedOut:
    44.                 Debug.LogError("Connection Timed Out!");
    45.                 break;
    46.  
    47.             // The request didn't finished in the given time.
    48.             case HTTPRequestStates.TimedOut:
    49.                 Debug.LogError("Processing the request Timed Out!");
    50.                 break;
    51.         }
    52.     });
    53.  
    54.     request2.UseAlternateSSL = false;
    55.     request2.Send();
    56. }
    57.  
    58. public void Cargar_Foto_De_Perfil2(string perfil)
    59. {
    60.     HTTPRequest request = new HTTPRequest(new Uri(perfil), HTTPMethods.Get, (req, resp) =>
    61.     {
    62.         switch (req.State)
    63.         {
    64.             // The request finished without any problem.
    65.             case HTTPRequestStates.Finished:
    66.                 if (resp.IsSuccess)
    67.                 {
    68.                     var tex = new Texture2D(0, 0);
    69.                     tex.LoadImage(resp.Data); //Error here
    70.                          
    71.                     FOTO_DE_PERFILE.GetComponent<Image>().overrideSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
    72.                 }
    73.                 else // Internal server error?
    74.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    75.                                                     resp.StatusCode,
    76.                                                     resp.Message,
    77.                                                     resp.DataAsText));
    78.                 break;
    79.  
    80.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    81.             case HTTPRequestStates.Error:
    82.                 Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    83.                 break;
    84.  
    85.             // The request aborted, initiated by the user.
    86.             case HTTPRequestStates.Aborted:
    87.                 Debug.LogWarning("Request Aborted!");
    88.                 break;
    89.  
    90.             // Connecting to the server is timed out.
    91.             case HTTPRequestStates.ConnectionTimedOut:
    92.                 Debug.LogError("Connection Timed Out!");
    93.                 break;
    94.  
    95.             // The request didn't finished in the given time.
    96.             case HTTPRequestStates.TimedOut:
    97.                 Debug.LogError("Processing the request Timed Out!");
    98.                 break;
    99.         }
    100.     });
    101.     request.UseAlternateSSL = false;
    102.     request.Send();
    103.  
    104.     m_Thread = new System.Threading.Thread(Cargar_Grupos);
    105.     m_Thread.Start();
    106. }
     
  40. xpxilom

    xpxilom

    Joined:
    Aug 28, 2014
    Posts:
    30
    Ready, I worked.


    I love you. You are the best...

    This is one of the best buys I've cast all my life, and the best support of my story I resivido. THANK YOU:
     
    BestHTTP likes this.
  41. MySchoolLife

    MySchoolLife

    Joined:
    Dec 21, 2013
    Posts:
    4
    Hello

    I recently upgrade from best http pro 1.9.9.but Websocket echo example is not working.
    (Best Http Pro Ver : 1.9.13 (2016.07.20))
    (Unity3D 5.3.6f1)

    When I Click Open Web Socket Button, error was occured.

    Opening Web Socket...
    -An error occured: Unknown Error
     
    Last edited: Aug 25, 2016
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,653
    @MySchoolLife
    There is a bug in 1.9.13 where if there are no trailing / in the url, it will fail to connect. By default the echo sample will try to connect to "wss://echo.websocket.org", if you change it to "wss://echo.websocket.org/" it should be able to connect.
     
  43. light530

    light530

    Joined:
    Aug 30, 2016
    Posts:
    12
    Hello

    I've tested to download a file from server by using the asset bundle sample.
    I found that the response code become 200 and 304(not modified) alternatively but i didn't change the file on server actually.
    Is that mean if 304 is responded, it will directly use the cache in storage without downloading the content again?
    And 200 means it will download those again?

    How can i ensure it will not download the content again if no content is modified?
     
  44. BestHTTP

    BestHTTP

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

    Yes.
    Yes.

    Here is a good explanation on caching, you can follow all the guidance you can find: https://developers.google.com/web/f...ce/optimizing-content-efficiency/http-caching

    As far as i know the client should work as it's described here.
     
  45. light530

    light530

    Joined:
    Aug 30, 2016
    Posts:
    12
    OK, the reference you provided works by sending a header(If-None-Match) with the responded etag and return 304 successfully. But another problem occurs. The cache file is deleted after running send request alternatively and causes error. It seems to be that the cache file was not added to UsedIndexes and then it deletes the cache file. How to solve it?
     
  46. BestHTTP

    BestHTTP

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

    Are you setting the header manually? Because caching and cache validation is done automatically and transparently by the plugin.
     
    Last edited: Aug 31, 2016
  47. light530

    light530

    Joined:
    Aug 30, 2016
    Posts:
    12
    yes, i just try to set the header by using setHeader function.
    Is that wrong or how can i do?
     
  48. light530

    light530

    Joined:
    Aug 30, 2016
    Posts:
    12
    Oh, I found that the header (If-None-Match) is set automatically in source code...
    But why the cache file is deleted automatically?
     
  49. BestHTTP

    BestHTTP

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

    Can you send an url that I can test this behavior on?
     
  50. tedlofgren

    tedlofgren

    Joined:
    Apr 16, 2015
    Posts:
    4
    Hi!

    First off; Thanks for a great plugin!

    Second; I would like to report a crash when terminating the application on iOS.

    Code (CSharp):
    1.  Non-fatal Exception: SocketException - The socket has been shut down
    2. System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) (System)
    3. System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) (System)
    4. Org.BouncyCastle.Crypto.Tls.RecordStream.WriteRecord (Byte type, System.Byte[] plaintext, Int32 plaintextOffset, Int32 plaintextLength) (Org)
    5. Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeWriteRecord (Byte type, System.Byte[] buf, Int32 offset, Int32 len) (Org)
    6. Org.BouncyCastle.Crypto.Tls.TlsProtocol.RaiseAlert (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause) (Org)
    7. Org.BouncyCastle.Crypto.Tls.TlsProtocol.HandleClose (Boolean user_canceled) (Org)
    8. BestHTTP.HTTPManager.OnQuit () (BestHTTP)
    9. BestHTTP.HTTPUpdateDelegator.OnApplicationQuit () (BestHTTP)
    10. Rethrow as IOException: Write failure
    11. System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) (System)
    12. Org.BouncyCastle.Crypto.Tls.RecordStream.WriteRecord (Byte type, System.Byte[] plaintext, Int32 plaintextOffset, Int32 plaintextLength) (Org)
    13. Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeWriteRecord (Byte type, System.Byte[] buf, Int32 offset, Int32 len) (Org)
    14. Org.BouncyCastle.Crypto.Tls.TlsProtocol.RaiseAlert (Byte alertLevel, Byte alertDescription, System.String message, System.Exception cause) (Org)
    15. Org.BouncyCastle.Crypto.Tls.TlsProtocol.HandleClose (Boolean user_canceled) (Org)
    16. BestHTTP.HTTPManager.OnQuit () (BestHTTP)
    17. BestHTTP.HTTPUpdateDelegator.OnApplicationQuit () (BestHTTP)
    Thanks

    @BestHTTP
     
    Last edited: Sep 1, 2016