Search Unity

Best HTTP Released

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

  1. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    @BestHTTP Thank you again for being so great at answering my questions! I moved onto grabbing Websocket data now.
    The documentation says that I am getting a textual response from the socket. I thought I could pull out data from the message by following the other methods you showed me for the REST API calls, but my web server developer is telling me I have to use a different library to decode websocket messages than REST/ HTTP responses. I tried using "unescape" but the data still wasn't able to be parsed.
    Can you point me to example code to capture data from a text response such as being able to set string active = data["active"] and string id = data["id"] ? I am not sure if that is how that works.
    -Message received: {0} a["{\"active\": true, \"id\": 4, \"}"]
     
  2. gg67

    gg67

    Joined:
    Jul 26, 2013
    Posts:
    19
    Just upgraded to 1.8.1 and caching is not working as expected. Items correctly cache while the client is running, and when I close the client, the cached file is still in the cache folder. However, when I launch the client again and hit the url of the cached file, the cache file disappears and is redownloaded and cached.

    Any idea what could be going on?
     
  3. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan : What is exatly the message you receive and you have to parse? The "["{\"active\": true, \"id\": 4, \"}"]" string looks like a valid json, although it's a list that contains one string "{\"active\": true, \"id\": 4, \"}" (with an unnecessary ',' (comma) and double quote at the end).
     
  4. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Sent you a mail with a fix.
     
  5. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    The whole message I get from the webSocket looks like this when I look in the console:
    Message received: {0}
    a["{\"_type\": \"poll\", \"description\": \"It's awesome.\", \"question\": \"Which answer is the most awesome?\", \"answers\": [19, 20, 21], \"pollresponse_set\": [21, 23, 24, 25], \"user\": 3, \"active\": true, \"id\": 5, \"channel\": \"polls|section:1\", \"name\": \"Awesome Poll of Awesomeness\"}"]
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan: It's still not clear what message the server sending. Can you share how you log the received message? If you receive only ["{\"_type\": \"poll\", \"description\": \"It's awesome.\", \"question\": \"Which answer is the most awesome?\", \"answers\": [19, 20, 21], \"pollresponse_set\": [21, 23, 24, 25], \"user\": 3, \"active\": true, \"id\": 5, \"channel\": \"polls|section:1\", \"name\": \"Awesome Poll of Awesomeness\"}"] then the list's first and only element a json string again that you can decode again:

    Code (CSharp):
    1. string json = @"[""{\""_type\"": \""poll\"", \""description\"": \""It's awesome.\"", \""question\"": \""Which answer is the most awesome?\"", \""answers\"": [19, 20, 21], \""pollresponse_set\"": [21, 23, 24, 25], \""user\"": 3, \""active\"": true, \""id\"": 5, \""channel\"": \""polls|section:1\"", \""name\"": \""Awesome Poll of Awesomeness\""}""]";
    2. var listData = Json.Decode(json) as List<object>;
    3. var data = Json.Decode(listData[0] as string) as Dictionary<string, object>;
    4.  
    5. foreach (var kvp in data)
    6. {
    7.    Debug.Log(string.Format("{0}:{1}", kvp.Key, kvp.Value));
    8. }
     
  7. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    I bought Best HTTP(Pro).
    I want to use Socket.IO in WebGL Build in the feature.
    Will you support this?
     
  8. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @kyubuns: I plan to support it, but i don't know yet, when. Maybe around the end of the year, early next year.
     
  9. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    I'm looking forward to it.
    thanks
     
  10. JMEA

    JMEA

    Joined:
    Sep 27, 2013
    Posts:
    23
    I added BestHTTP Pro to my project and it increased the uncompresased iOS executable by almost 15M. Are there any parts of the library I can strip or remove? Is this expected due to the il2cpp code size issues?
     
  11. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    I am using this code to get the message:
    Code (CSharp):
    1. void OnMessageReceived(WebSocketws, stringmessage)
    2. {
    3. Debug.Log("-Message received: {0}\n" + message);
    4. string json = message;
    5. var listData = Json.Decode (json) asList<object>;
    6. var data = Json.Decode (listData [0] asstring) asDictionary<string, object>;
    7.  
    8. foreach (varkvpindata) {
    9. Debug.Log (string.Format ("{0}:{1}", kvp.Key, kvp.Value));
    10. }}
    The response is in the Unity editor console, which prints:
    -Message received: {0}
    a["{\"_type\": \"poll\", \"description\": \"It's awesome.\", \"question\": \"Which answer is the most awesome?\", \"answers\": [19, 20, 21], \"pollresponse_set\": [], \"user\": 3, \"active\": true, \"id\": 5, \"channel\": \"poll:5|multiplayeractivity:3\", \"name\": \"Awesome Poll of Awesomeness\"}"]
    UnityEngine.Debug:Log(Object)
    getthatlist:OnMessageReceived(WebSocket, String) (at Assets/Scripts/Networking/getthatlist.cs:83)
    BestHTTP.WebSocket.WebSocket:<OnInternalRequestUpgraded>m__13(WebSocketResponse, String) (at Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocket.cs:262)
    BestHTTP.WebSocket.WebSocketResponse:HandleEvents() (at Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocketResponse.cs:355)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:504)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:49)

    Which is fine, and then when I try the code to get the data it fails at line 86:
    var data = Json.Decode (listData [0] asstring) asDictionary<string, object>;:
    Ex [WebSocketResponse]: HandleEvents - Message: Object reference not set to an instance of an object StackTrace: at getthatlist.OnMessageReceived (BestHTTP.WebSocket.WebSocket ws, System.String message) [0x0001e] in /Users/mPerry/June18Backup/Assets/Scripts/Networking/getthatlist.cs:86
    at BestHTTP.WebSocket.WebSocket.<OnInternalRequestUpgraded>m__13 (BestHTTP.WebSocket.WebSocketResponse ws, System.String msg) [0x0000b] in /Users/mPerry/June18Backup/Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocket.cs:262
    at BestHTTP.WebSocket.WebSocketResponse.HandleEvents () [0x00079] in /Users/mPerry/June18Backup/Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocketResponse.cs:355
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Exception(String, String, Exception) (at Assets/Best HTTP (Pro)/BestHTTP/Logger/DefaultLogger.cs:89)
    BestHTTP.WebSocket.WebSocketResponse:HandleEvents() (at Assets/Best HTTP (Pro)/BestHTTP/WebSocket/WebSocketResponse.cs:370)
    BestHTTP.HTTPManager:OnUpdate() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPManager.cs:504)
    BestHTTP.HTTPUpdateDelegator:Update() (at Assets/Best HTTP (Pro)/BestHTTP/HTTPUpdateDelegator.cs:49)
     
  12. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @JMEA: IL2CPP adds a little more to the build size, but you can try to set stripping on your project. With stripping it should be around 4 MB.
     
  13. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan: Don't know why, your message contains a leading 'a' character that renders the string to an invalid json string. It must came from the server that you are connected. I think you should ask the server guy how you should parse the received string.
     
  14. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    So ... after a long day of fiddling with this on my end, the web server dev told me he doesn't know why there is an "a" at the beginning. Now I'm trying to catch messages where the first char is "a", and Substring the "a" off, and then grab data from the array. Is this normal? Most websockets enabled sites send data that looks much more usable.
     
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    It would be good to know why it's there, but until then you can use something like this to remove the 'a' char and decode the json string:
    Code (csharp):
    1.  
    2. string json = @"a[""{\""_type\"": \""poll\"", \""description\"": \""It's awesome.\"", \""question\"": \""Which answer is the most awesome?\"", \""answers\"": [19, 20, 21], \""pollresponse_set\"": [], \""user\"": 3, \""active\"": true, \""id\"": 5, \""channel\"": \""poll:5|multiplayeractivity:3\"", \""name\"": \""Awesome Poll of Awesomeness\""}""]";
    3. var listData = BestHTTP.JSON.Json.Decode(json.Substring(1)) as List<object>;
    4. var data = BestHTTP.JSON.Json.Decode(listData[0] as string) as Dictionary<string, object>;
    5.  
    6. foreach(var kvp in data)
    7. {
    8.  Debug.Log(kvp.Key + " : " + kvp.Value);
    9. }
    10.  
     
  16. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    Wow, that's pretty elegant, I never would have thought of that! Thank you again!
     
  17. MartinCA

    MartinCA

    Joined:
    Jan 1, 2012
    Posts:
    15
    Hey,

    We're using BestHTTP in our project and we've run into a problem when trying to build for iOS.
    When building for iOS the build fails with an AOT compiler error saying it can't resolve a reference to WWWForm::get_headers() (which is the auto generated property getter for the headers field in WWWForm if I'm not mistaken). The error originates when trying to AOT compile BestHTTP.dll (already left the office so I don't have a full output log on hand, but it was not much more informative than that).

    As far as setup goes, we're using Unity5.1.1 (latest release, tried updating today from 5.0.1 hoping it would resolve the issue). Stripping is disabled and .NET profile is set to .Net 2.0. This happens both when trying to compile using the mono scripting backend and when trying to compile using IL2CPP universal target (the output message is slightly different, but it all traces back to WWWForm.get_headers).

    Also, I have the links.xml referencing the crypto lib in the root of my assets folder (I don't have any additional plugins in the project, so I just copied it as is).

    I would appreciate any help in trying to resolve this issue, and thanks in advance for reading through this.

    Also, I'd like to thank you for the great plugin, I really like the API design and the documentation is great - and it performs great on Android and desktop :)
     
  18. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @MartinCA: I'm on a trip currently, so i can give you only a rough solution now. I will be back in my office next week only to investigate it deeper.
    As you have the Basic version you can't remove files, so in a private message i will send you a link where you can download the Pro version. Before upgrading you have to delete the BestHTTP.dlls from the Plugin folder(and from the WP8 and Metro subfolders).
    Hopefully with the Pro version you can build your project already. If not, you can remove the /Assets/Best HTTP (Pro)/BestHTTP/Forms/Implementations/UnityForm.cs. It's a legacy implementation, and not used by default. If you not set a request's FormUsage to HTTPFormUsage.Unity then you are good to go.
    So, after this step you will still get some compile errors, so you have to delete two lines in the /Assets/Best HTTP (Pro)/BestHTTP/HTTPRequest.cs:
    -at line 525
    -and at 572

    As you will see these already doesn't compiled into the WP8 versions. As i remember Unity's WP8 implementation doesn't have the WWWForm::get_headers() too.

    So, basically with two little steps you have to remove the class itself and all referencies to it. After this it should build no successfully.
     
    Last edited: Jul 2, 2015
  19. MadByteLabs

    MadByteLabs

    Joined:
    May 29, 2011
    Posts:
    18
    Hi i use BestHTTP with https://github.com/mrniko/netty-socketio
    I call
    Code (CSharp):
    1. private void Start ()
    2.     {
    3.         SocketOptions options = new SocketOptions ();
    4.  
    5.         options.AutoConnect = false;
    6.  
    7.         SocketManager manager = new SocketManager (new Uri ("http://localhost:9090/socket.io/"), options);
    8.    
    9.         manager.Socket.On (SocketIOEventTypes.Connect, (socket, receivedPacket, args) => Debug.LogError ("---Connect---"));
    10.  
    11.         manager.Socket.On (SocketIOEventTypes.Error, (socket, packet, args) => Debug.LogError (string.Format ("Error: {0}", args [0].ToString ())));
    12.        
    13.         manager.Open ();
    14.     }
    and receive an error on the server side

    Code (CSharp):
    1. io.netty.channel.DefaultChannelPipeline$TailContext exceptionCaught
    2. WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
    3. java.lang.NumberFormatException: For input string: "true"
    If use another client lib, connect is profit. Thanks.
     
  20. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Lestar: Checked netty's source and my best bet now is the b64 parameter of the requests. You can find and replace all occurences of the b64=true and replace it to b64=1. One located in the /Socket.IO/HandshakeData.cs and the others in the /Socket.IO/Transports/PollingTransport.cs.
    Let me know how it works.
     
  21. MadByteLabs

    MadByteLabs

    Joined:
    May 29, 2011
    Posts:
    18
    It's work. Thanks.
     
  22. MartinCA

    MartinCA

    Joined:
    Jan 1, 2012
    Posts:
    15
    Applied the suggested fix and everything works perfectly on all platforms - Thanks!
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Thank you for the update.
    I'm back in my office and was able to reproduce it. There are two versions in the Asset Store for the Basic version. One for Unity 4.x and one for Unity 5.x. For users, Unity will show the version that appropriate for the user's Unity version. So it's transparent for the users, but there are on catch:
    You probably started the project with Unity 4.x and downloaded the plugin with it, then when upgraded Unity to 5.x the plugin wasn't updated. So the plugin used for Unity 5.x that compiled against Unity 4.x.

    If you would update the plugin from Unity 5.x then the error should go.
     
  24. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    Hello Again! I hope everyone had a pleasant weekend.
    I have a question about Cookies. If I use HTTP REST or Websockets, I have been setting an Auth string manually by grabbing it from a browser and pasting it into my scripts.

    For Example:
    webSocket.Send("[{\"route\":\"chat-route\",\"verb\":\"chat\",\"args\":{\"auth\":\"33f4d97857448de05b9d64833a7370e19afcbc1e\",\"message\":\"Hello!\"},\"callbackname\":\"cb_7\"}]");

    If I use Basic Authentication with BestHTTP will I no longer have to set the "auth" part of the "args"?

    Is there a simple way to grab the cookie from the server, or from the cookie jar?

    I have been trying to figure out how to access new cookies sent by the server through the response’s Cookies property. (per the BestHTTP documentation)
    I made sure to include BestHTTP.Cookies; at the top.
    Code (CSharp):
    1.     IEnumerator Start() {
    2.             WWW www = new WWW(url);
    3.             yield return www;
    4.          
    5.             if(www.responseHeaders.Count > 0) {
    6.                 foreach(KeyValuePair<string, string> entry in www.responseHeaders) {
    7.                     Debug.Log(entry.Value + "=" + entry.Key);
    8.                 }
    9.             }
    The response I get in the Console is:

    Cookie=VARY
    UnityEngine.Debug:Log(Object)
    <Start>c__Iterator6:MoveNext() (at Assets/Scripts/Networking/CookieExample.cs:29)


    But what I'm really trying to get is the "auth_token" "33f4d97857448de05b9d64833a7370e19afcbc1e" for example. I could then set it to a string and reference that when I send data out.
     
    Last edited: Jul 7, 2015
  25. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan

    It depends on what your server supports.
    In your example code you sent the "auth" value in a websocket message json encoded.
    Basic authentication will set the Authorization header.
    Cookie based authentication will set a cookie with the proper token.

    These are three different ways, and the server can support all of them simultaneously.

    Unity's WWW only stores the last header value for a given header. A server may set multiple Cookie header, but with WWW you will get only the last one.
    With BestHTTP you can get a list for a header(usually containing only one element, but as with cookies, the RFC for HTTP allows multiple headers with the same name):

    Code (CSharp):
    1. var request = new HTTPRequest(new Uri("http://server.com"), (req, resp) =>
    2. {
    3.     Debug.Log("Received Cookies:");
    4.     if (resp.Cookies != null)
    5.         foreach (var cookie in resp.Cookies)
    6.         {
    7.             Debug.Log(cookie.ToString());
    8.         }
    9. });
    10. request.Send();
    11.  
     
  26. hoyeon-c

    hoyeon-c

    Joined:
    Jul 8, 2015
    Posts:
    4
    I could not connect to the Https server using SocketManager and keep getting a connection error.
    Is there any other option to connect to the Https server?
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @hoyeon.c: It's most probably the default SSL handler. You can try to switch to the alternate one by setting the HTTPManager's UseAlternateSSLDefaultValue to true:
    Code (CSharp):
    1. BestHTTP.HTTPManager.UseAlternateSSLDefaultValue = true;
    By setting this, all request will use the BouncyCastle implementation.
     
  28. hoyeon-c

    hoyeon-c

    Joined:
    Jul 8, 2015
    Posts:
    4
    solve it.

    WebSocketTransport.cs

    Uri uri = new Uri(string.Format("{0}?transport=websocket&sid={1}{2}",
    new UriBuilder(Manager.Uri.Scheme, Manager.Uri.Host, Manager.Uri.Port, Manager.Uri.PathAndQuery).Uri.ToString(),
    Manager.Handshake.Sid,
    !Manager.Options.QueryParamsOnlyForHandshake ? Manager.Options.BuildQueryParams() : string.Empty));
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @hoyeon.c : Good catch. It should be something like this:
    Code (CSharp):
    1. Uri uri = new Uri(string.Format("{0}?transport=websocket&sid={1}{2}",
    2.                                     new UriBuilder(HTTPProtocolFactory.IsSecureProtocol(Manager.Uri) ? "wss" : "ws",
    3.                                                 Manager.Uri.Host,
    4.                                                 Manager.Uri.Port,
    5.                                                 Manager.Uri.PathAndQuery).Uri.ToString(),
    6.                                     Manager.Handshake.Sid,
    7.                                     !Manager.Options.QueryParamsOnlyForHandshake ? Manager.Options.BuildQueryParams() : string.Empty));
    Will test it, and will include the fix in the next update.
     
  30. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    I've been trying everything to get a list of cookies, but with the code
    Code (CSharp):
    1.  foreach (var cookie in resp.Cookies)
    2.         {
    3.             Debug.Log(cookie.ToString());
    4.         }
    I only get the CSRF token , instead of all the Set-Cookie strings. I do get them by using Python, with this code:
    Code (CSharp):
    1. import requests
    2.  
    3.  
    4. host = 'http://staging.mywebsite.com'
    5. data = {
    6.     'login': 'admin',
    7.     'password': ‘pw’,
    8. }
    9. args = {
    10.     'data': data,
    11.     'allow_redirects': False,
    12. }
    13. response = requests.post('%s/en/accounts/login/?next=/dashboard/' % host, **args)
    14. auth_token = response.cookies['auth_token']
    My Unity script looks like this:
    Code (CSharp):
    1.     public void testAuth()
    2.     {
    3.         HTTPRequest request = new HTTPRequest (new Uri ("http://www.staging.myurl.com/en/accounts/login/?next=/dashboard/"), HTTPMethods.Post, OnRequestFinished);
    4.         request.AddField ("login", "admin");
    5.         request.AddField ("password", "pw");
    6. //        request.AddField ("csrfmiddlewaretoken", "zD9pQzMXeG2tEEgVPjtJd1waxF99yT84");
    7.         request.Send ();
    8.        
    9.     }
    10.     void OnRequestFinished(HTTPRequest request, HTTPResponse response)
    11.     {
    12.         Debug.Log("Request Finished! Text received: " + response.DataAsText);
    13.         if (response.Cookies != null)
    14.             foreach (var cookie in response.Cookies)
    15.         {
    16.             Debug.Log(cookie.ToString());
    17.         };
    18.     }
    This gives me a response with the error: h1>Forbidden <span>(403)</span></h1>
    <p>CSRF verification failed. Request aborted.</p>

    I'm not sure why the python example works with the server, but the C# example gets rejected. Do you have any insight on how to get the "auth_token" instead of the "csrftoken"?
     
  31. TRsiew

    TRsiew

    Joined:
    Jul 5, 2013
    Posts:
    13
    i have some question about SocketIO

    I have using SocketManager class to connect server , by first i can receive data from server .

    but after i test few times , that is nothing receive data from server again .

    no error at all .

    What are the problems caused?I
     
  32. TRsiew

    TRsiew

    Joined:
    Jul 5, 2013
    Posts:
    13
    i have some problem about Socket.IO

    i using SocketManager to connect and receive data from server . by first , i can receive any data from server , but after i tested few times , i can not receive data from server and no error at all . it's still connected on server . but just can not receive any data from server .

    do you have any idea about this problem ?
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @Dynamoid Megan
    Can you send me the url that you are using and a test account? Just the code doesn't help too much now.
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @TRsiew : Can you send me a repro-project?
    Are you received any errors on the server?
    Also, by setting the loglevel to a more verbose one, you may find suspicious messages:
    Code (CSharp):
    1. BestHTTP.HTTPManager.Logger.Level = BestHTTP.Logger.Loglevels.All;
     
  35. jluhman

    jluhman

    Joined:
    Mar 8, 2014
    Posts:
    2
    I purchased BestHTTP Pro and downloaded version 1.8.2. Do the Windows Store and Windows Phone platforms work in this version? Here is what I see:

    1) Import BestHTTP - the plugin folders appear to be moved automatically on import into Assets/Plugins (Metro and WP8).
    2) When I set my project to build the Windows Store app, I get a message:
    "Plugin 'TcpClientImplementation.dll' is used from several locations:
    Assets/Plugins/Metro/TcpClientImplementation.dll would be copied to <PluginPath>/TcpClientImplementation.dll
    Assets/Plugins/TcpClientImplementation.dll would be copied to <PluginPath>/TcpClientImplementation.dll
    Please fix plugin settings and try again."

    3) So I go to TCPClientImplementation.dll in the unity project under plugins. I see that after import, "Any Platform" is checked. Is this correct? I thought no - so I unchecked that, and checked all boxes EXCEPT WSAPlayer and WP8Player.

    4) When I build the Windows Store app again, I now get the following errors:

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

    Assets\Best HTTP (Pro)\BestHTTP\HTTPConnection.cs(17,19): error CS0246: The type or namespace name 'SocketEx' could not be found (are you missing a using directive or an assembly reference?)


    Assets\Best HTTP (Pro)\BestHTTP\HTTPManager.cs(144,23): error CS0246: The type or namespace name 'Org' could not be found (are you missing a using directive or an assembly reference?)

    Assets\Best HTTP (Pro)\BestHTTP\HTTPRequest.cs(295,16): error CS0246: The type or namespace name 'Org' could not be found (are you missing a using directive or an assembly reference?)

    Shouldn't my build be pulling in the TcpClientImplementation.dll from the Metro folder, and shouldn't that contain the assembly references that are missing?

    Using Unity 5.1.0.f3 Pro

    PS. Stand-alone build works fine. And the project runs fine in the Editor. WP8 build does not work. It reports similar errors (but not identical).

    PPS. I can recreate this with a brand-new Unity project, importing no packages except BestHTTP. An empty windows project with only BestHTTP in it will not build.

    PPPS. Unity 4.6, installed on the same machine works fine with an empty project using only BestHTTP. The Windows Store project builds.
     
    Last edited: Jul 10, 2015
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @jluhman You were on the right path to fix, but one step left. For /Assets/Plugins/Metro/TcpClientImplementation.dll you have to set the 'Placeholder' setting to /Assets/Plugins/TcpClientImplementation.dll.

    It's an old problem, and i thought that if i set the right setting it will persist in the exported package, but unfortunately no...
     
  37. leetful

    leetful

    Joined:
    Feb 23, 2013
    Posts:
    16
    I am attempting to use besthttp pro with socket.io & am receieveing the error: Err [HandshakeData]: Handshake request failed with error: Parsing Handshake data failed: <!doctype html>

    Would you know of this error?
     
  38. chooser

    chooser

    Joined:
    Mar 21, 2015
    Posts:
    13
    Can I use besthttp with UniRx?
    (free asset of Reactive Extensions for Unity)
    I encountered thread error.
     
    Last edited: Jul 13, 2015
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    The handshake request returned with a non-valid handshake data. As you can see it starts with an "<!doctype html>" string, so the server sent a most probably error page. The most common error is the missing socket.io/ path from the uri:
    Code (CSharp):
    1. Manager = new SocketManager(new Uri("http://localhost:3030/socket.io/"), options);
    Instead of a pure
    Code (CSharp):
    1. Manager = new SocketManager(new Uri("http://localhost:3030"), options);
    Also, some Socket.IO servers requries additional parameters.
     
  40. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @chooser: Not used yet, however it looks very promising.

    Can you describe how you use it and what errors are you encountered? (A repro project would help a lot, i think.)
     
    Last edited: Jul 13, 2015
  41. leetful

    leetful

    Joined:
    Feb 23, 2013
    Posts:
    16
    thanks for the response could you give me an example of connection? I am not sure how to format the options required?
    Thanks again.
     
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @leetful : You can use it without the options:
    Code (CSharp):
    1. Manager = new SocketManager(new Uri("http://localhost:3030/socket.io/"));
     
  43. leetful

    leetful

    Joined:
    Feb 23, 2013
    Posts:
    16
    I tried that and got this:

    Err [HandshakeData]: Handshake request failed with error: Connection refused at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
     
  44. leetful

    leetful

    Joined:
    Feb 23, 2013
    Posts:
    16
    Nm! Wrong port. Thanks for help. My apologies.
     
  45. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Code (csharp):
    1. BestHTTP.Caching.HTTPCacheService.BeginClear();
    Question: does the above work for anyone else on Android with Unity 5.x? I get a crash and the adb shows some threading anger. I also found that the above crashes on iOS with Unity5.x when not compiling with IL2CPP. Not a major issue there as we need to use IL2CPP anyways, but just mention it as an FYI.

    None of this is a very hot issue for our project because we are controlling caching on our server anyway, but wondering if there are any known gotcha's with that function.
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    @slumtrimpet : I will double check it, and will make sure that it works.
     
  47. TRsiew

    TRsiew

    Joined:
    Jul 5, 2013
    Posts:
    13
    thank , it fixed .

    i have other question
    Code (CSharp):
    1.  
    2. void userLogin()
    3. {
    4.         HTTPRequest request = new HTTPRequest(new System.Uri("uri/user/login"), HTTPMethods.Get, OnFinish);
    5.         request.Send();
    6. }
    7.  
    8. void OnFinish(HTTPRequestreq, HTTPResponseresp)
    9.  {
    10. Debug.Log(resp.DataAsText);
    11.  }
    12. void postFunction()
    13.  {
    14. HTTPRequestrequest = newHTTPRequest(newSystem.Uri("uri/api/game"), HTTPMethods.Post,OnPost);
    15. request.Credentials=newBestHTTP.Authentication.Credentials("aaaa1","aaaa1");
    16.  
    17. request.AddField("gold_amount", "100");
    18. request.AddField("game_name", "Fun");
    19. request.AddField("fight_duration", "60sec");
    20. request.Send();
    21.  }
    22.  
    23. voidOnPost(HTTPRequestreq, HTTPResponseresp)
    24.  {
    25. Debug.Log(resp.DataAsText);
    26.  }
    27.  
    by first , i call the userLogin(), after that call postFunction() . userLogin() will print the function it is login , but i can not post the data in my server . that will print out
    Code (CSharp):
    1. {"error":true,"data":null,"code":0,"message":"Invalid user.","action":"create"}
    Why will this happen? which step wrong ?
     
  48. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Didn't you should receive a user Id ( or something ) that you can identify the user with, and send it with the Post request?
     
  49. TRsiew

    TRsiew

    Joined:
    Jul 5, 2013
    Posts:
    13
    I received my user id , but how i can identify the user id and send it? any sample can let me see and test?
     
  50. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Well, it depends on how you received it(in a header, in a cookie, in the response), in what format(plain text, in a json object, xml), and how the server expects it.