Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best HTTP Released

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

  1. jgold

    jgold

    Joined:
    Feb 26, 2015
    Posts:
    6
    I get the following exception while trying to send a request when compiling for iOS with IL2CPP in Unity 4.6.3p2.

    EXCEPTION: System.IO.IOException: The authentication or decryption has failed. ---> System.NotSupportedException: Unsupported security protocol type
    at Mono.Math.BigInteger+Kernel.Multiply (System.UInt32[] x, UInt32 xOffset, UInt32 xLen, System.UInt32[] y, UInt32 yOffset, UInt32 yLen, System.UInt32[] d, UInt32 dOffset) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Context.DecodeProtocolCode (Int16 code) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHello.processProtocol (Int16 protocol) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHello.ProcessAsTls1 () [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.checkDomainName (System.String subjectName) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    at System.AsyncCallback.Invoke (IAsyncResult ar) [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at System.Net.Sockets.Socket+SocketAsyncResult.Complete () [0x00000] in <filename unknown>:0
    at System.Net.Sockets.Socket+Worker.Receive () [0x00000] in <filename unknown>:0
    at unibill.Dummy.Factory..ctor () [0x00000] in <filename unknown>:0
    --- End of inner exception stack trace ---
    at Mono.Math.BigInteger+Kernel.Multiply (System.UInt32[] x, UInt32 xOffset, UInt32 xLen, System.UInt32[] y, UInt32 yOffset, UInt32 yLen, System.UInt32[] d, UInt32 dOffset) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    at unibill.Dummy.Factory..ctor () [0x00000] in <filename unknown>:0
    Stack trace:
    at BestHTTP.OnRequestFinishedDelegate.Invoke(BestHTTP.HTTPRequest originalRequest, BestHTTP.HTTPResponse response)
    at BestHTTP.SocketIO.Error.ToString()
    at BestHTTP.HTTPRequest.CallCallback()
    at BestHTTP.HTTPConnection.HandleCallback()
    at BestHTTP.HTTPManager.OnUpdate()
    at BestHTTP.HTTPUpdateDelegator.Update()
    at unibill.Dummy.Factory..ctor()
    EXCEPTION: System.IO.IOException: The authentication or decryption has failed. ---> System.NotSupportedException: Unsupported security protocol type
    at Mono.Math.BigInteger+Kernel.Multiply (System.UInt32[] x, UInt32 xOffset, UInt32 xLen, System.UInt32[] y, UInt32 yOffset, UInt32 yLen, System.UInt32[] d, UInt32 dOffset) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Context.DecodeProtocolCode (Int16 code) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHello.processProtocol (Int16 protocol) [0x00000] in <filename unknoexwn>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerHello.ProcessAsTls1 () [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.checkDomainName (System.String subjectName) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    at System.AsyncCallback.Invoke (IAsyncResult ar) [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at System.Net.Sockets.Socket+SocketAsyncResult.Complete () [0x00000] in <filename unknown>:0
    at System.Net.Sockets.Socket+Worker.Receive () [0x00000] in <filename unknown>:0
    at unibill.Dummy.Factory..ctor () [0x00000] in <filename unknown>:0

    I've also tried to build for Mono 2.x and get this exception:

    Ex [HTTPRequest]: SendOutTo - Message: Attempting to JIT compile method '(wrapper managed-to-native) System.Threading.Interlocked:CompareExchange (System.Collections.Concurrent.ConcurrentStack`1/Node<byte[]>&,System.Collections.Concurrent.ConcurrentStack`1/Node<byte[]>,System.Collections.Concurrent.ConcurrentStack`1/Node<byte[]>)' while running with --aot-only. StackTrace: at System.Collections.Concurrent.ConcurrentStack`1[System.Byte[]].Push (System.Byte[] item) [0x00000] in <filename unknown>:0 at Microsoft.IO.RecyclableMemoryStreamManager.ReturnBlocks (ICollection`1 blocks, System.String tag) [0x00000] in <filename unknown>:0 at Microsoft.IO.RecyclableMemoryStream.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 at Microsoft.IO.RecyclableMemoryStream.Close () [0x00000] in <filename unknown>:0 at System.IO.Stream.Dispose () [0x00000] in <filename unknown>:0 at BestHTTP.HTTPRequest.SendOutTo (System.IO.Stream stream) [0x00000] in <filename unknown>:0

    Everything works fine when running through the editor or via PC standalone build. Let me know if you need more information.
     
  2. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    It's reported to Unity, they are working on it. For a possible workaround you may try to set the request's UseAlternateSSL property to true.

    Sent you a download link to an updated package. The same is uploaded to the Asset Store, but it's still in Pending Review state.
     
  3. jgold

    jgold

    Joined:
    Feb 26, 2015
    Posts:
    6
    Thanks for the quick response! I've updated to the package you provided.

    Using alternate SSL in IL2CPP is still no go. I get a different exception:

    EXCEPTION: System.IO.IOException: Internal TLS error, this could be an attack
    at Org.BouncyCastle.Crypto.Tls.DefaultTlsAgreementCredentials..ctor (Org.BouncyCastle.Crypto.Tls.Certificate certificate, Org.BouncyCastle.Crypto.AsymmetricKeyParameter privateKey) [0x00000] in <filename unknown>:0
    at Org.BouncyCastle.Crypto.Tls.TlsProtocol.InvalidateSession () [0x00000] in <filename unknown>:0
    at Org.BouncyCastle.Crypto.Tls.UrlAndHash.Parse (TlsContext context, System.IO.Stream input) [0x00000] in <filename unknown>:0
    at Org.BouncyCastle.Crypto.Tls.TlsProtocol.SafeReadRecord () [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at Org.BouncyCastle.Crypto.Tls.TlsProtocol.CompleteHandshake () [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at Org.BouncyCastle.Crypto.Tls.TlsClientProtocol.Connect (TlsClient tlsClient) [0x00000] in <filename unknown>:0
    at JsonFx.Json.TypeCoercionUtility.CoerceArray (System.Type elementType, IEnumerable value) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.Connect () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0
    at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <filename unknown>:0
    at unibill.Dummy.Factory..ctor () [0x00000] in <filename unknown>:0

    It looks like the new package fixed the Mono build however.
     
  4. blueteak

    blueteak

    Joined:
    Feb 19, 2013
    Posts:
    140
    I wasn't able to get the basic version to work correctly on iOS using best http in my current application with IL2CPP, so I created a new one to test it out, here is my code that works in the editor:

    public void Click ()
    {

    HTTPRequest req = newHTTPRequest(new Uri(url), onFinish);
    req.Send();
    }

    void onFinish(HTTPRequest req, HTTPResponse response)
    {

    PlaneObj.material.mainTexture = response.DataAsTexture2D;
    }

    And here is the error in XCode after running the Click() method:

    Ex [HTTPRequest]: CallCallback - Message: A null value was found where an object instance was required. StackTrace: at <PrivateImplementationDetails>..ctor () [0x00000] in <filename unknown>:0
    at TestRun.onFinish (BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse response) [0x00000] in <filename unknown>:0
    at BestHTTP.OnRequestFinishedDelegate.Invoke (BestHTTP.HTTPRequest originalRequest, BestHTTP.HTTPResponse response) [0x00000] in <filename unknown>:0
    at BestHTTP.WebSocket.WebSocketResponse.BestHTTP.Extensions.IHeartbeat.OnHeartbeatUpdate (TimeSpan dif) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPRequest.CallCallback () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.HandleCallback () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPManager.OnUpdate () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPUpdateDelegator.Update () [0x00000] in <filename unknown>:0
    at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in <filename unknown>:0
    Replacements.MSCompatUnicodeTable:get_IsReady()
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:LogError(Object)
    BestHTTP.Logger.DefaultLogger:Exception(String, String, Exception)
    BestHTTP.HTTPConnection:<Connect>b__0(Object, X509Certificate, X509Chain, SslPolicyErrors)
    BestHTTP.HTTPRequest:CallCallback()
    BestHTTP.HTTPConnection:HandleCallback()
    BestHTTP.HTTPManager:OnUpdate()
    BestHTTP.HTTPUpdateDelegator:Update()
    Replacements.MSCompatUnicodeTable:get_IsReady()
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebug.gen.cpp Line: 56)

    Using Unity 5, compiles fine with IL2CPP - .Net 2.0, and works completely using the Mono, just throws error with IL2CPP and image never shows up (onFinish never called).
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Did some tests, and reported a bug with a repro project to Unity.
     
  6. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Can you make sure that the PlanceObj isn't null? My texture download sample working fine with IL2CPP.
    Also you can enchant the onFinished function with a more robust handling:

    Code (CSharp):
    1. void onFinish(HTTPRequest req, HTTPResponse resp)
    2. {
    3.     switch (req.State)
    4.     {
    5.         // The request finished without any problem.
    6.         case HTTPRequestStates.Finished:
    7.             if (resp.IsSuccess)
    8.             {
    9.                 PlaneObj.material.mainTexture = resp.DataAsTexture2D;
    10.             }
    11.             else
    12.                 Debug.LogWarning(string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    13.                                                 resp.StatusCode,
    14.                                                 resp.Message,
    15.                                                 resp.DataAsText));
    16.             break;
    17.  
    18.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    19.         case HTTPRequestStates.Error:
    20.             Debug.LogError("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    21.             break;
    22.  
    23.         // The request aborted, initiated by the user.
    24.         case HTTPRequestStates.Aborted:
    25.             Debug.LogWarning("Request Aborted!");
    26.             break;
    27.  
    28.         // Ceonnecting to the server is timed out.
    29.         case HTTPRequestStates.ConnectionTimedOut:
    30.             Debug.LogError("Connection Timed Out!");
    31.             break;
    32.  
    33.         // The request didn't finished in the given time.
    34.         case HTTPRequestStates.TimedOut:
    35.             Debug.LogError("Processing the request Timed Out!");
    36.             break;
    37.     }
    38. }
    This way we can get more details if something gone bad.
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Version 1.7.5 released in the Asset Store.

    Release notes of this release:
    • [New Feature] New Priority property in the HTTPRequest class to be able prioritize queued requests
    • [Improvement] Additional GC alloc improvements
    • [Bugfix] Fixed a possible crash in the plugin under iOS
     
  8. blueteak

    blueteak

    Joined:
    Feb 19, 2013
    Posts:
    140
    Thanks for the more detailed onFinish code, here is the error:

    Request Finished with Error! The authentication or decryption has failed.
    at Mono.Math.BigInteger+Kernel.Multiply (System.UInt32[] x, UInt32 xOffset, UInt32 xLen, System.UInt32[] y, UInt32 yOffset, UInt32 yLen, System.UInt32[] d, UInt32 dOffset) [0x00000] in <filename unknown>:0
    at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    at Replacements.MSCompatUnicodeTable.get_IsReady ()

    I am using an https:// url, but it works correctly in the editor and with Mono 2.x
    Here's the url: https://www.looktracker.com/wp-content/uploads/2014/06/Choose-Eye-Tracking-User-Test-Website-URL.png

    I will update to 1.7.5 and see if that fixes it.

    EDIT: 1.7.5 throws the UnusedBytecodeStripper2 error even when set to .Net 2.0
     
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663


    It's a bug on Unity's end. It's already reported.

    Yeah, sorry this was my mistake, I have a new version waiting for aproval... Until this, i will send the download link of that new package. That should fix this issue.
     
  10. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
    hi im try to use socket.io pro edition.

    how to set port number in socket.io?
     
  11. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    You can set it like this:
    Code (CSharp):
    1. SocketManager manager = new SocketManager(new Uri("http://localhost:3000/socket.io/"));
     
  12. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
    if i try like that, only return 'Invalid handshake text: Welcome to socket.io.' error message.

    why is this happening?
     
    Last edited: Mar 10, 2015
  13. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Are you appended the /socket.io/ path to your url? It's the most common problem for handshake errors.
     
  14. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
  15. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    What are you using on server side?
    For example sails.js requires additional parameters to send, so it can cause problems.
     
  16. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I find it strange that plugin works on Windows Phone device only if you build and run it from Visual Studio.
    If you build and run it from Unity3D it throws "AggregateException: One or more errors occurred.".

    Any suggestions ?
     
  17. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Just checked on my L920, but it's worked fine. Can you send me what exception is in the AggregateException's InnerException(s)?
     
  18. mfav

    mfav

    Joined:
    Aug 27, 2014
    Posts:
    5
    Hey, great plugin.

    My use case is to stream audio via POST to a server. I have tried following your examples of using a FileStream to upload, but it doesn't seem to carry over to using a MemoryStream.

    Specifically, I am writing to a MemoryStream progressively with a series of bytes (audio samples). This buffer is of variable length, users may stream anywhere from 1-10 seconds of samples. After setting up the HTTP request, I include the following parameters:
    Code (CSharp):
    1.         request.UseUploadStreamLength = false; // length is variable
    2.         request.OnUploadProgress += OnUploadProgress; // to see progress
    3.         request.UploadStream = CurrentStream; // CurrentStream is of type MemoryStream
    4.         request.Send();
    Here are my issues:

    1. Is there a way to progressively stream a buffer as it's written to? If I try to Send() the request after the first bit of the buffer is written, it will only send my first bit of samples (256), and not the subsequent ones which are written to the stream.
    2. On the other hand, if I fully write to the MemoryStream first, THEN Send() the stream, it still does not work. The server on the other end is not reporting that it is receiving data. Whereas, if I use request.RawData = MyStream.ToArray(), the data is sent as expected, implying the stream is properly set-up.
    3. In either case, the OnUploadProgress callback is never called.

    Ideally, I can progressively stream via POST, otherwise I don't see the purpose of the streaming class other than a progress bar. At any rate, I can't stream whatsoever using BestHTTP - which is my entire goal with using it! Please let me know if there's any suggestions you can offer or how I can take a better approach.
     
  19. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Lumia 435 here. The same exception as if internet connection was off. "No such host is known. (Exception from HRESULT: 0x80072AF9)".
    It takes about 10 seconds to throw it, but without internet connection it's instant.

    Added this to OnError event.
    Code (csharp):
    1. Text += ex.InnerException.Message + "\n" + ex.StackTrace + "\n";
     
    Last edited: Mar 13, 2015
  20. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
    is not support get handshake?

    how to get handshake address
     
  21. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    There are two problems:
    1. The plugin has a bug sending the UploadStream, I will send a download link to an updated package after I write this post. This bug prevents the upload progress report too.
    2. A MemoryStream isn't the best choice for a streamed upload, becouse when there are no more data in it, Read will return -1. When this happens the plugin will think that all data are sent, and will finish the upload. So the Stream's Read should return -1 only when there will be no more data to upload.
    Pasting a complete example here. The UploadStream is a Stream implementation that will return -1 only when you called the Finish() function, and all remaining data are read from it. I used to MemoryStream, one for writing to and one for reading from. When we read all data from the read buffer, we will switch the two buffers. Also becouse the Read function is called from an other thread then the Write, we need to do some thread synchronization too. It's just a quick implementation, but a working one.

    Let me know how it works.

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3.  
    4. using UnityEngine;
    5. using BestHTTP;
    6. using System.Collections;
    7. using System.IO;
    8. using System.Threading;
    9.  
    10. public sealed class UploadStream : Stream
    11. {
    12.     MemoryStream ReadBuffer = new MemoryStream();
    13.     MemoryStream WriteBuffer = new MemoryStream();
    14.     AutoResetEvent ARE = new AutoResetEvent(false);
    15.     bool noMoreData;
    16.     object locker = new object();
    17.  
    18.     public UploadStream()
    19.     {
    20.         ReadBuffer = new MemoryStream();
    21.         WriteBuffer = new MemoryStream();
    22.     }
    23.  
    24.     public override int Read(byte[] buffer, int offset, int count)
    25.     {
    26.         int read = -1;
    27.  
    28.         // We will not push more data to the write buffer
    29.         if (noMoreData)
    30.         {
    31.             // No data left in the read buffer
    32.             if (ReadBuffer.Position == ReadBuffer.Length)
    33.             {
    34.                 // Is there any data in the write buffer? If so, switch the buffers
    35.                 if (WriteBuffer.Length > 0)
    36.                     SwitchBuffers();
    37.                 else
    38.                     return -1;
    39.             }
    40.             else
    41.                 return ReadBuffer.Read(buffer, offset, count);
    42.         }
    43.  
    44.         // There are no more data in the read buffer? Wait for it.
    45.         if (ReadBuffer.Position == ReadBuffer.Length)
    46.             ARE.WaitOne();
    47.  
    48.         lock (locker)
    49.             read = ReadBuffer.Read(buffer, offset, count);
    50.  
    51.         return read;
    52.     }
    53.  
    54.     public override void Write(byte[] buffer, int offset, int count)
    55.     {
    56.         if (noMoreData)
    57.             throw new System.ArgumentException("noMoreData already set!");
    58.  
    59.         lock (locker)
    60.         {
    61.             WriteBuffer.Write(buffer, offset, count);
    62.  
    63.             SwitchBuffers();
    64.         }
    65.  
    66.         ARE.Set();
    67.     }
    68.  
    69.     public void Finish()
    70.     {
    71.         noMoreData = true;
    72.  
    73.         ARE.Set();
    74.     }
    75.  
    76.     private bool SwitchBuffers()
    77.     {
    78.         // Switch the buffers only when all data are consumed from our read buffer
    79.         lock (locker)
    80.         {
    81.             if (ReadBuffer.Position == ReadBuffer.Length)
    82.             {
    83.                 // This buffer will be the read buffer, we need to seek back to the beginning
    84.                 WriteBuffer.Seek(0, SeekOrigin.Begin);
    85.  
    86.                 // This will be the write buffer, set the length to zero
    87.                 ReadBuffer.SetLength(0);
    88.  
    89.                 // switch the two buffers
    90.                 MemoryStream tmp = WriteBuffer;
    91.                 WriteBuffer = ReadBuffer;
    92.                 ReadBuffer = tmp;
    93.  
    94.                 return true;
    95.             }
    96.         }
    97.  
    98.         return false;
    99.     }
    100.  
    101.     protected override void Dispose(bool disposing)
    102.     {
    103.         if (disposing)
    104.         {
    105.             ReadBuffer.Dispose();
    106.             ReadBuffer = null;
    107.  
    108.             WriteBuffer.Dispose();
    109.             WriteBuffer = null;
    110.  
    111.             ARE.Close();
    112.             ARE = null;
    113.         }
    114.  
    115.         base.Dispose(disposing);
    116.     }
    117.  
    118.     #region Not Implemented Functions and Properties
    119.  
    120.     public override bool CanRead { get { throw new NotImplementedException(); } }
    121.     public override bool CanSeek { get { throw new NotImplementedException(); } }
    122.     public override bool CanWrite { get { throw new NotImplementedException(); } }
    123.  
    124.     public override long Length { get { throw new NotImplementedException(); } }
    125.     public override long Position { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } }
    126.  
    127.     public override void Flush()
    128.     {
    129.         throw new NotImplementedException();
    130.     }
    131.  
    132.     public override long Seek(long offset, SeekOrigin origin)
    133.     {
    134.         throw new NotImplementedException();
    135.     }
    136.  
    137.     public override void SetLength(long value)
    138.     {
    139.         throw new NotImplementedException();
    140.     }
    141.  
    142.     #endregion
    143. }
    144.  
    145. public sealed class UploadStreamTest : MonoBehaviour
    146. {
    147.     public int iterations = 10;
    148.     public float iterationWaitTimeInSec = 1f;
    149.     public int chunkSize = 256;
    150.  
    151.     HTTPRequest request;
    152.    
    153.     void OnGUI()
    154.     {
    155.         if (request == null && GUILayout.Button("Send Request"))
    156.             SendRequest();
    157.     }
    158.  
    159.     IEnumerator FillStream()
    160.     {
    161.         int sent = 0;
    162.         byte[] chunk = new byte[chunkSize];
    163.  
    164.         //yield return new WaitForSeconds(1f);
    165.  
    166.         while (sent++ < iterations)
    167.         {
    168.             // wait 1 sec
    169.             yield return new WaitForSeconds(iterationWaitTimeInSec);
    170.  
    171.             // fill up the chunk buffer with data
    172.             for (int i = 0; i < chunk.Length; ++i)
    173.                 chunk[i] = (byte)(i % 256);
    174.  
    175.             // write the buffer to our upload buffer
    176.             request.UploadStream.Write(chunk, 0, chunk.Length);
    177.         }
    178.  
    179.         // This must be called when we do not want to write more data to it.
    180.         // Instead of Finish, we may implement it in the overridden Flush function. In this case we
    181.         //  wouldn't need to cast it.
    182.         (request.UploadStream as UploadStream).Finish();
    183.     }
    184.  
    185.     void SendRequest()
    186.     {
    187.         // create a new request
    188.         request = new HTTPRequest(new Uri("http://httpbin.org/post"), HTTPMethods.Post, OnRequestFinished);
    189.  
    190.         // set up upload progress report
    191.         request.OnUploadProgress = (req, up, length) => Debug.Log("Uploaded: " + up.ToString("N0") + " / " + length.ToString("N0"));
    192.  
    193.         // create a new stream
    194.         request.UploadStream = new UploadStream();
    195.  
    196.         // we don't know the length
    197.         request.UseUploadStreamLength = false;
    198.  
    199.         // send the request
    200.         request.Send();
    201.  
    202.         // start filling up the upload stream with data
    203.         StartCoroutine(FillStream());
    204.     }
    205.  
    206.     void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
    207.     {
    208.         request = null;
    209.  
    210.         switch (req.State)
    211.         {
    212.             // The request finished without any problem.
    213.             case HTTPRequestStates.Finished:
    214.                 if (resp.IsSuccess)
    215.                 {
    216.                     Debug.Log("Request Finished Successfully! Data length: " + resp.Data.Length + " " + resp.DataAsText);
    217.                 }
    218.                 else
    219.                     Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    220.                                                     resp.StatusCode,
    221.                                                     resp.Message,
    222.                                                     resp.DataAsText));
    223.                 break;
    224.  
    225.             // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    226.             case HTTPRequestStates.Error:
    227.                 Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    228.                 break;
    229.  
    230.             // The request aborted, initiated by the user.
    231.             case HTTPRequestStates.Aborted:
    232.                 Debug.LogWarning("Request Aborted!");
    233.                 break;
    234.  
    235.             // Ceonnecting to the server is timed out.
    236.             case HTTPRequestStates.ConnectionTimedOut:
    237.                 Debug.LogError("Connection Timed Out!");
    238.                 break;
    239.  
    240.             // The request didn't finished in the given time.
    241.             case HTTPRequestStates.TimedOut:
    242.                 Debug.LogError("Processing the request Timed Out!");
    243.                 break;
    244.         }
    245.     }
    246. }
     
  22. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    The plugin wil use the Uri that you passed to the manager. The request is located in the HandshakeData.cs's Start function:
    Code (CSharp):
    1. HandshakeRequest = new HTTPRequest(new Uri(string.Format("{0}?EIO={1}&transport=polling&t={2}-{3}&b64=true",
    2.                                                             Manager.Uri.ToString(),
    3.                                                             SocketManager.MinProtocolVersion,
    4.                                                             Manager.Timestamp,
    5.                                                             Manager.RequestCounter++)),
    6.                                    OnHandshakeCallback);
    7.  
    Here you can add additional parameters too, if you want.
     
  23. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Tried again now with Unity 4.6. Created a new project, downloaded and imported the plugin from the asset store. Switched platform to "Windows Phone 8" and made a Build & Run. It's worked fine. My first guess was that the networking capability doesn't set by Unity. But it worked, and when opened the generated project the capability was there with a checked state.

    Let's go forward. Switched platform to "Windows Store" and SDK to "Phone 8.1". Hitting the Build & Run i receive a cryptic "An error 0x81030136 occurred while running: 0x81030136" error message after the app installed on the device. When i launch it manually, however i receive the "One or more errors occured" message. Bingo. No "Internet" capability was set by Unity. Opened the solution with Visual Studio, checked the Capabilities tab: no capabilityes are checked. Started it from VS, and it's worked... Hmm, strange.

    Deleted the solution and the app from the device. Back to Unity.
    tl;dr: Under Player Settings../Publishing Settings checked the InternetClient capability, then it's worked with Build&Run.

    Targeting WP8 wasn't able to find how i can set the capabilities from Unity.
     
  24. mfav

    mfav

    Joined:
    Aug 27, 2014
    Posts:
    5
    This is excellent help, thank you very much.

    Unfortunately, I've been tinkering with your example and I still seem to be encountering an issue. My coroutine code for writing is as follows:
    Code (CSharp):
    1. IEnumerator StreamData() {
    2.   while (!streamingComplete) {
    3.     yield return new WaitForFixedUpdate();
    4.     if (newDataArrived) {
    5.       request.UploadStream.Write(currentPacket.Data, 0, currentPacket.Length);
    6.       newDataArrived = false;
    7.     }
    8.   }
    9.   (request.UploadStreamasUploadStream).Finish();
    10. }
    Using your new UploadStream class and HTTPRequest.cs file. However, the stream is immediately disposed of, causing a Null Pointer Exception on the write. The streamingComplete remains true, but stream still finishes early. I have tried setting request.DisposeUploadStream to false but that doesn't solve the issue either since it stops consuming the stream to read.
     
  25. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I work on Unity 5 and building for Universal 8.1, sorry I forgot to mention that.
    Well, setting these capabilities still didn't do the trick. It's most likely a bug on Unity's end.
    Thank you for your help and excellent plugin.

    UPD: Owait, I've deleted the solution and the application, rebuilt it from Unity, and now it finally worked. OMG sweet.
    So yeah, it was all about setting the right capabilities.
    Yet another 5 stars from me.
     
    Last edited: Mar 13, 2015
  26. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Strange. Is my sample working for you?
    Can you modify my sample (or make a repro project if it's easier for you) so i can debug it out?

    You can set the DisposeUploadStream back to true, i will be called after the plugin thinks that it uploaded the whole stream(the streams Read function returned -1). So the big question is, why returned -1 earlier than it should.
     
  27. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Great! And thank you. :)
     
  28. mfav

    mfav

    Joined:
    Aug 27, 2014
    Posts:
    5
    I can reproduce fairly easily. With your example, try setting the iterationWaitTimeInSec to something small, 0.1 or less. If you do that, you'll notice the stream closes prematurely and a null pointer results.

    In my circumstance, the samples are being written out at very short intervals like this. I can make the packet size larger (and thus a larger interval), but I think this bug(?) may be causing other issues too.
     
  29. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Thank you, i was able to reproduce it.
     
  30. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    @mfav Please try it with the attached UploadStream class. Made some changes to prevent this problem, and also formatted it to feel it more complete. :)
     

    Attached Files:

  31. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
    thx i found it.

    i have one more question.

    i called handshake, and return data format like this 'sid:heartbeatinterval:connectioninterval:websocket'

    so it makes parsing problem. how to fixed it?
     
    Last edited: Mar 16, 2015
  32. steve.salmond

    steve.salmond

    Joined:
    Jan 29, 2013
    Posts:
    8
    Hi there,

    Was wondering if line 874 of HTTPRequest in method SendOutTo() should read:
    Code (CSharp):
    1. if (data != null || UploadStream != null)
    Seems like it's possible to have a case where an UploadStream is specified but RawData is null. Does that modification make sense or would it break something?

    Cheers,
    Steve
     
  33. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    The b64=true parameter in the uri of the handshake should control the return value. If it's there and its value is true, then the server have to return a json formatted data. Please, make sure that you don't overwritten it.
     
  34. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    No, it should be there. Fixed in the next update, but it's just doesn't released yet. Sorry.
     
  35. threesevenGod

    threesevenGod

    Joined:
    Mar 10, 2015
    Posts:
    7
    In client?

    How to check this? and I found that the contents shown below.

    On 0.9.4:

    response: 9svmBRkeQuECcpw6ZGPK:60:60:websocket,htmlfile,xhr-polling,jsonp-polling

    On 1.0.4:

    response: �0{"sid":"ySaqnVO4pJajP_TfAAAM","upgrades":["websocket"],"pingInterval":25000,"pingTimeou....

    -
    i guess, this problem seems to be caused by our server socket.io version is low than this asset version.
     
  36. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663

    Yes, on the client, in the HandshakeData.cs.
    And yes, that server a little old for the plugin. :) It's written and tested agains Socket.IO 1.+
     
  37. gshape

    gshape

    Joined:
    Aug 8, 2012
    Posts:
    104
    Hi! I just purchased BestHTTP and like it! thanks.

    I get the following exception while trying to decompress a response when compiling for iOS with IL2CPP in Unity 5.0.0f4.

    DecompressString - System Error! Ionic.Zlib.ZlibException: Bad state (incomplete dynamic bit lengths tree)

    at Ionic.Zip.ZipOutputStream.get_Encryption () [0x00000] in <filename unknown>:0

    at Ionic.Zlib.InflateManager.Inflate (FlushType flush) [0x00000] in <filename unknown>:0

    at Ionic.Zlib.ZlibCodec.Inflate (FlushType flush) [0x00000] in <filename unknown>:0

    at Ionic.Zlib.ZlibBaseStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.JsonSerializerSettings.set_Error (System.EventHandler`1 value) [0x00000] in <filename unknown>:0

    at Ionic.Zlib.GZipStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.JsonSerializerSettings.set_Error (System.EventHandler`1 value) [0x00000] in <filename unknown>:0

    at System.IO.StreamReader.ReadBuffer () [0x00000] in <filename unknown>:0

    at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0

    at Ionic.Crc.CrcCalculatorStream..cctor () [0x00000] in <filename unknown>:0

    at System.IO.StreamReader.ReadToEnd () [0x00000] in <filename unknown>:0

    at FingerGestures+GlobalTouchFilterDelegate.EndInvoke (IAsyncResult result) [0x00000] in <filename unknown>:0

    at ControllerOnline.DecompressString (System.String compressed) [0x00000] in <filename unknown>:0

    at ControllerOnline+<RegisterPlayer>c__Iterator6C.MoveNext () [0x00000] in <filename unknown>:0

    at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in <filename unknown>:0

    Replacements.MSCompatUnicodeTable:get_IsReady()

    UnityEngine.Debug:Internal_Log(Int32, String, Object)

    UnityEngine.Debug:LogError(Object)

    ControllerOnline:DecompressString(String)

    <RegisterPlayer>c__Iterator6C:MoveNext()

    Replacements.MSCompatUnicodeTable:get_IsReady()

    I saw that you mentioned there is a unity bug about Gzip-ed response can produce an “Bad state (incomplete dynamic bit lengths tree)” error. A workaround to this issue is setting the “Accept-Encoding” header to “identity”

    Indeed, I have added the workaround but it doesn't seem work.
    Code (CSharp):
    1. HTTPRequest request = new HTTPRequest(new Uri(registerURL),
    2.                                               HTTPMethods.Post,
    3.                                               OnRequestFinished_RegisterPlayer);
    4.  
    5.         request.AddField("playerName", submittedName);
    6.         request.SetHeader("Accept-Encoding", "identity");
    7.         request.Send();
    This is the decompress function i have now.
    Code (CSharp):
    1.     public static string DecompressString(string compressed)
    2.     {
    3.         try
    4.         {
    5.             Debug.Log("---- DecompressString ---- : " + compressed);
    6.  
    7.             byte[] compressedBytes = Convert.FromBase64String(compressed);
    8.             //Debug.Log("compressedBytes: " + Convert.ToBase64String(compressedBytes));
    9.  
    10.             return GZipStream.UncompressString(compressedBytes);
    11.         }
    12.         catch(System.Exception e)
    13.         {
    14.             //instance.ctm.ShowMessage("System Error! " + e.ToString(), false);
    15.             Debug.LogError("DecompressString - System Error! " + e.ToString());
    16.  
    17.             return string.Empty;
    18.         }
    19.     }
    Could you please kindly advice?
    Thanks.


    P.S. everything works fine in Editor, but not on the iOS device.
     
    Last edited: Mar 19, 2015
  38. gshape

    gshape

    Joined:
    Aug 8, 2012
    Posts:
    104
  39. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    Great! Just wanted to write that you should try out the latest patch. :)
    And I forgot to update the docs too.
     
  40. HappiPlay

    HappiPlay

    Joined:
    May 21, 2013
    Posts:
    8
    Hi, we got an error in il2cpp(u5) we think that might cause of your zlib calu method.
    Bad state (invalid stored block lengths)
    at BestHTTP.Authentication.Digest.GenerateResponseHeader (BestHTTP.HTTPRequest request, BestHTTP.Authentication.Credentials credentials) [0x00000] in <filename unknown>:0
    at BestHTTP.Decompression.Zlib.InflateManager.Inflate (FlushType flush) [0x00000] in <filename unknown>:0
    at BestHTTP.Decompression.Zlib.ZlibCodec.Inflate (FlushType flush) [0x00000] in <filename unknown>:0
    at BestHTTP.Decompression.Zlib.ZlibBaseStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
    at BestHTTP.SocketIO.SocketOptions.set_AutoConnect (Boolean value) [0x00000] in <filename unknown>:0
    at BestHTTP.Decompression.Zlib.GZipStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
    at BestHTTP.SocketIO.SocketOptions.set_AutoConnect (Boolean value) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPResponse.DecodeStream (System.IO.Stream streamToDecode) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPResponse.ReadChunked (System.IO.Stream stream) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPResponse.Receive (Int32 forceReadRawContentLength, Boolean readPayloadData) [0x00000] in <filename unknown>:0
    at BestHTTP.SocketIO.SocketOptions.set_AutoConnect (Boolean value) [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.Receive () [0x00000] in <filename unknown>:0
    at BestHTTP.HTTPConnection.ThreadFunc (System.Object param) [0x00000] in <filename unknown>:0
    at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <filename unknown>:0
    at Replacements.MSCompatUnicodeTable.get_IsReady () [0x00000] in <filename unknown>:0



    We had passed all tests in editor or iOS(mono) only cause error in il2cpp. We think that may happen in larger files.
    I could give you the test url cause this error.
     
  41. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    It's fixed in Unity 5's first patch release (5.0.0p1). Please update your Unity 5 installation, and let me know how it works, it must be fixed.
     
  42. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    There are two releases too, that i didn't posted about. Version 1.7.6 already released, 1.7.7 is in a "Pending Review" state and hopefully it will be released soon.

    Release notes of these:
    • 1.7.7 (2015.03.17)
    [New Feature] Socket.IO’s SocketOptions has two new property to control additional query parameters of the requests
    [Improvement] New UploadStream.cs in the Examples folder to help and demonstrate uploading streams
    [Bugfix] UploadStream upload not worked​

    • 1.7.6 (2015.03.07)
    [New Feature] New CustomCertificateVerifyer property to the HTTPRequest class to be able to set custom validator for the AlternateSSL handler too
    [Improvement] Improved Unity5 compatibility​
     
  43. chooser

    chooser

    Joined:
    Mar 21, 2015
    Posts:
    13
    Hi
    I have some question

    1. OnDownloadProgress

    protected void OnDownloadProgress(HTTPRequestrequest,intdownloaded,intlength)
    {
    Debug.Log("Downloaded:"+downloaded.ToString());
    Debug.Log("length:"+length.ToString());
    }

    request.OnProgress=OnDownloadProgress;

    I write down this code and get these log
    ----------------------------
    Downloaded: 777
    length: 777
    Downloaded: 777
    length: 777
    ----------------------------

    That's all how can I get whole downloading bytes
    I think OnDownloadProgress will call more than two times.

    2. How Can I post multiple part data

    request.AddField("filecomment", "some first comment");
    request.AddBinaryData("file",firstfile);

    request.AddField("filecomment", "some second comment");
    request.AddBinaryData("file",secondfile);

    And error with already add key
    How to send more than two data with some data Key.

    3. I just compare with iOS7 and iOS8 then iOS8 get very slow....
    (Sometimes the response is null or timeout <- I set 15 seconds)
    Just 1.0MB data and iOS7 is fine.

    How come iOS8 is very slow...
    Do I need some additional code? Or setting?

    Please help me
     
  44. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    1. OnDownloadProgress: When the server send the data with chunked encoding, the client can't calculate what will be the whole size of the download(length). With this case, the OnDownloadProgress will always report the actual chunk's progress. There is a high chance that your server sent the data in chunks that has a length of 777 bytes.

    2. You can add multiple fields, but you have to choice different identifiers as field names:
    Code (CSharp):
    1. request.AddField("filecomment_1", "some first comment");
    2. request.AddBinaryData("file_1",firstfile);
    3. request.AddField("filecomment_2", "some second comment");
    4. request.AddBinaryData("file_2",secondfile);
    3. Didn't noticed any differencies between the two versions, and it's running just fine on iOS 8. Are you targeting the new IL2CPP scripting backend?
     
    chooser likes this.
  45. chooser

    chooser

    Joined:
    Mar 21, 2015
    Posts:
    13
    Thank-you for quick reply

    1.
    >: When the server send the data with chunked encoding, the client can't calculate what will be the whole size of the download(length)

    OK, I see. Gonna try another way.

    2.
    Hum.... I can not use same identifiers......
    I have to discuss with API team

    3.
    >Are you targeting the new IL2CPP scripting backend?
    I don't know about "IL2CPP" I will check it again,
    Anyway the problem was not code you mean right?.

    Thank you for your kind reply
    Best regards,
    Chooser
     
  46. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    The very same code runs on all versions of iOS, so it shouldn't be becouse of code differencies.
     
    chooser likes this.
  47. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,663
    I was curious, so checked the code and wrote a little test. I didn't store the added fields/binary datas in a Dictionary, so i don't know where are the "already added key" errors from.

    I got no error for this code:
    Code (CSharp):
    1. var request = new HTTPRequest(new Uri("http://httpbin.org/post"), HTTPMethods.Post, (req, resp) =>
    2. {
    3.     switch (req.State)
    4.     {
    5.         // The request finished without any problem.
    6.         case HTTPRequestStates.Finished:
    7.             if (resp.IsSuccess)
    8.             {
    9.                 Debug.Log("Request Finished Successfully! " + resp.DataAsText);
    10.             }
    11.             else
    12.                 Debug.LogWarning(string.Format("Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
    13.                                                 resp.StatusCode,
    14.                                                 resp.Message,
    15.                                                 resp.DataAsText));
    16.             break;
    17.  
    18.         // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
    19.         case HTTPRequestStates.Error:
    20.             Debug.LogWarning("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
    21.             break;
    22.  
    23.         // The request aborted, initiated by the user.
    24.         case HTTPRequestStates.Aborted:
    25.             Debug.LogWarning("Request Aborted!");
    26.             break;
    27.  
    28.         // Ceonnecting to the server is timed out.
    29.         case HTTPRequestStates.ConnectionTimedOut:
    30.             Debug.LogError("Connection Timed Out!");
    31.             break;
    32.  
    33.         // The request didn't finished in the given time.
    34.         case HTTPRequestStates.TimedOut:
    35.             Debug.LogError("Processing the request Timed Out!");
    36.             break;
    37.     }
    38. });
    39.  
    40. request.AddField("filecomment", "some first comment");
    41. request.AddBinaryData("file", new byte[10]);
    42.  
    43. request.AddField("filecomment", "some second comment");
    44. request.AddBinaryData("file", new byte[20]);
    45.  
    46. request.Send();
    The response is something like this:
    Request Finished Successfully! {
    "args": {},
    "data": "",
    "files": {
    "file": "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
    },
    "form": {
    "filecomment": [
    "some first comment",
    "some second comment"
    ]
    },
    "headers": {
    "Accept-Encoding": "gzip, identity",
    "Content-Length": "627",
    "Content-Type": "multipart/form-data; boundary=\"37775B00\"",
    "Host": "httpbin.org",
    "Te": "identity",
    "User-Agent": "BestHTTP"
    },
    "json": null,
    "url": "http://httpbin.org/post"
    }

    However there are only one "file" field, it should be a server side problem, as for the "filecomment" field all sent data are present.
     
    chooser likes this.
  48. stgs73

    stgs73

    Joined:
    Mar 23, 2015
    Posts:
    59
    Hi, i just purchased BestHTTP - getting some success which is great, however i am having a hell of a time with the node.js server - i am calling emit on the Socket.IO but the client is simply not getting the callback. I am on iOS, Unity 5 and this is all in the editor. I've probably done something wrong with the server code but can anyone throw up the code, at least for the Socket.IO server example ? thnx
     
  49. Kanda

    Kanda

    Joined:
    Oct 9, 2014
    Posts:
    1
    Hi, Ive updated Unity to 5.0.0p1, but i am getting a EXC_BAD_ACCESS in XCode using and iOS device and IL2CPP using code that works in editor and on iOS device with Mono. The problem seems to occur when i create two HTTPRequest objects right after each other in my function. I get the following output in XCode, if this info is of any use:

    Code (CSharp):
    1. thrive`il2cpp::icalls::System::System::Net::Sockets::Socket::Send(Il2CppIntPtr, Il2CppArray*, int, int, il2cpp::icalls::System::System::Net::Sockets::SocketFlags, int*) at Socket.cpp:1031:
    2. 0x21985c8:  push   {r4, r5, r6, r7, lr}
    3. 0x21985cc:  add    r7, sp, #0xc
    4. 0x21985d0:  str    r8, [sp, #-4]!
    5. 0x21985d4:  sub    sp, sp, #0x8
    6. 0x21985d8:  ldr    r6, [r7, #12]
    7. 0x21985dc:  mov    r4, r0
    8. 0x21985e0:  mov    r0, #0x0
    9. 0x21985e4:  mov    r5, r3
    10. 0x21985e8:  str    r0, [r6]
    11. 0x21985ec:  ldr    r3, [r1, #12]
    12. 0x21985f0:  sub    r3, r3, r5
    13. 0x21985f4:  cmp    r3, r2
    14. 0x21985f8:  blt    0x2198648                 ; il2cpp::icalls::System::System::Net::Sockets::Socket::Send(Il2CppIntPtr, Il2CppArray*, int, int, il2cpp::icalls::System::System::Net::Sockets::SocketFlags, int*) + 128 at Socket.cpp:1052
    15. 0x21985fc:  mov    r0, r1
    16. 0x2198600:  mov    r1, #0x1
    17. 0x2198604:  ldr    r8, [r7, #8]
    18. 0x2198608:  bl     0x21a962c                 ; il2cpp_array_addr_with_size(Il2CppArray*, int, unsigned long)
    19. 0x219860c:  mov    r1, r0
    20. 0x2198610:  mov    r0, #0x0
    21. 0x2198614:  str    r0, [sp, #4]
    22. 0x2198618:  add    r0, sp, #0x4
    23. 0x219861c:  str    r0, [sp]
    24. 0x2198620:  mov    r0, r4
    25. 0x2198624:  mov    r2, r5
    26. 0x2198628:  mov    r3, r8
    27. 0x219862c:  bl     0x219cd08                 ; il2cpp::os::Socket::Send(unsigned char const*, int, il2cpp::os::SocketFlags, int*)
    28. 0x2198630:  cmp    r0, #0x1
    29. 0x2198634:  bne    0x2198644                 ; il2cpp::icalls::System::System::Net::Sockets::Socket::Send(Il2CppIntPtr, Il2CppArray*, int, int, il2cpp::icalls::System::System::Net::Sockets::SocketFlags, int*) + 124 at Socket.cpp:1051
    30. 0x2198638:  mov    r0, r4
    31. 0x219863c:  bl     0x219cc98                 ; il2cpp::os::Socket::GetLastError() const
    32. 0x2198640:  str    r0, [r6]
    33. 0x2198644:  ldr    r0, [sp, #4]
    34. 0x2198648:  sub    sp, r7, #0x10
    35. 0x219864c:  ldr    r8, [sp], #4
    36. 0x2198650:  pop    {r4, r5, r6, r7, pc}

    I have managed to avoid the error, if i wait with creating the second request after the first one has gotten a response, and its callback function has been called.
     
  50. stgs73

    stgs73

    Joined:
    Mar 23, 2015
    Posts:
    59
    It appears i am messing up with the handshake data, are the examples on the server, the routes actually redirecting to a html page somewhere with an io.connect on the server side? :/

    'Handshake request failed with error: Invalid handshake text: <!DOCTYPE html>'

    I am not using http://io.weplay.io/socket.io/ , i am using my own localhost so the socket.io/ should ne be required...

    I am literally taking the ''/' route and just trying to connect Socket.IO ....and i can't due the above issue.

    Anyway help appreciated.


    * Ok so the socket.io was needed, major booboo this end, sorry for the spam, all works now.
     
    Last edited: Mar 24, 2015