Search Unity

UniWeb

Discussion in 'Assets and Asset Store' started by simonwittber, May 23, 2013.

  1. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Simon, reporting a problem. I'm using WWWForm to post to a php. On PC, it works fine and on webplayer build, I get crossdomain policy error. . I setup the crossdomain, and it works with Unity WWW call but not HTTP

    Ok. I got it. uniweb uses socket internal so I need to setup the crossdomain socket and also call prefetchsocketpolicy for webplayer
     
    Last edited: Sep 28, 2013
  2. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    I'm using the wwwform post, it seems the Request Progress always return 0 or 1. Is there a way to get it working?
     
  3. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Hi Simon,

    I am using a local nodejs server and I am trying to call some http methods using HTTP.Request in UniWeb 1.9.19. But it always tells me that it's missing the crossdomain.xml.
    So, I added a new route called /crossdomain.xml. But in the server log, there is any call to the /crossdomain.xml but it keeps telling me that there is no crossdomain policy.
    Any idea concerning this issue ?

    btw: Any idea why UniParse is not in the AssetStore anymore ?

    Thanks a lot.
     
  4. Brad-Keys

    Brad-Keys

    Joined:
    May 1, 2006
    Posts:
    161
    Simon,

    I've been experimenting with Uniweb and noticed while running Unity's sockpol.exe that every request I make attempts to fetch the socket policy. Is this normal? I expected it would only attempt on the first call and after receiving it, it would no longer need to request the policy.

    It's a concern for me because it means we'll be getting twice as many requests if I set up my own socket server, and that's a big deal when we're getting millions of requests per day.

    Thanks.
     
  5. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    That strange, my plugin uses the same sockets for communicating with a server as UniWeb, but on my test server the sockpol executable logs only the first request.

    Maybe you can try to prefetch the policy manually using the Security.PrefetchSocketPolicy.
     
  6. Brad-Keys

    Brad-Keys

    Joined:
    May 1, 2006
    Posts:
    161
    Yes, that does seem to have fixed the problem. Thank you for the suggestion.

    It seems strange that I am required to use that even when I am using the default port. At least it works :)
     
  7. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Good, I'm glad that worked.
     
  8. Brad-Keys

    Brad-Keys

    Joined:
    May 1, 2006
    Posts:
    161
    I noticed that Prefetch doesn't work with the domain "localhost" and had to use the actual IP address. Will it work for registered domain names? I use a load balancer and won't know which IP address to target.
     
  9. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    I didn't used it, but i think it will work only with an IP address.

    But, fortunately you can use System.Net.Dns.GetHostAddresses to get an IP address from your domain name.
     
  10. Brad-Keys

    Brad-Keys

    Joined:
    May 1, 2006
    Posts:
    161
    Perfect, that does the trick! Thanks again.
     
  11. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    This has never happened to me. Can you please show some code to reproduce the problem?
     
  12. KamiKaze425

    KamiKaze425

    Joined:
    Nov 20, 2012
    Posts:
    207
    Code (csharp):
    1. var w = new WWWForm();
    2. w.AddField("stat1","123");
    3. w.AddField("stat2","13");
    4. w.AddField("score", "192");
    5. var request = new HTTP.Request("http://serverip/api/matchinfo", w);
    6. request.Send();
    7. while(!request.isDone)
    8. {
    9.    yield return new WaitForEndOfFrame();
    10. }
    11. if(request.exception != null)
    12. {
    13.    Debug.LogError(request.exception);
    14. }
    15. else
    16. {
    17.   //do stuff
    18. }
    that would post data twice on our server. but when I did it using the WWW class, it posted once. And I know for a fact that this method was only called once (print statements plus the fact that the WWW class didn't post twice)
     
  13. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
     
  14. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I think I responded to this via email, but in case anyone else sees this problem, it is explained in the README. I've also made a longer explanation here: http://entitycrisis.blogspot.com.au/2012/09/uniweb-www-and-crossdomainxml-explained.html
     
  15. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I've just run a test and confirm that the Progress field returns values in the range of 0.0 to 1.0. Is it possible your server is responding with such small messages that the transition from 0 to 1 happens over 1 frame?
     
  16. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Thanks for you great explanation on your blog, it solved my problem.
    Is it possible to extract an array of objects with JsonSerializer.Decode() ?
    Because it seems that an Arraylist is extracted with only Hashtable as values.

    Edit: It seems that you need to use List<> to populate your array.
     
    Last edited: Oct 14, 2013
  17. jasonFHH

    jasonFHH

    Joined:
    Jul 17, 2012
    Posts:
    21
    I bought my asset pre-Unity 4.0 (I'm a 3.5.7 user). I clicked "Update" and now UniWeb crashes all my projects (due to Unity 4.x incompatibility), but I have no way (that I'm aware of) to revert back to UniWeb that is compatible w/ Unity 3.5.7.


    I see a few other people have also asked about the Unity 3.5.7 issue. Any definitive answer on this? Our project is currently delayed since UniWeb was a core component :/

    Thanks!
     
  18. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I've been caught by that too, it seems any Unity4 package breaks a 3.5.7 project it is imported into.

    THe only thing to do is download using Unity4 free, then copy the files over into your new project manually, without the .meta files.
     
  19. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    I'm using UniParse and UniWeb ... iOS users (not seeing this on Android) have been reporting a problem where they'd play the game for a while, switch to another task, come back to the game, try to log in and get an 'invalid arguments' exception. I've managed to replicate this a couple of times by playing the game, backgrounding it and leaving it for 10+ mins then returning to it. The error appears to be coming from inside the #if USE_KEEPALIVE block so i'm removing that #def for now.

    This is the error, gets spammed to console 8 times when it's hit:

    Code (csharp):
    1. Invalid arguments >> System.Net.Sockets.SocketException: Invalid arguments
    2.   at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue) [0x00000] in <filename unknown>:0
    3.   at System.Net.Sockets.TcpClient.set_ReceiveTimeout (Int32 value) [0x00000] in <filename unknown>:0
    4.   at HTTP.ActiveConnection.get_Connected () [0x00000] in <filename unknown>:0
    5.   at HTTP.Request.GetClient (System.String host, Int32 port, Boolean useSsl) [0x00000] in <filename unknown>:0
    6.   at HTTP.Request.<Send>m__1C (System.Object t) [0x00000] in <filename unknown>:0  
     
  20. gdagley

    gdagley

    Joined:
    Jul 29, 2013
    Posts:
    6
    Has anyone seen this error when an iOS app has been in the background for a while (10 minutes or more) and then is opened. We are trying to make calls to the server when we come back from the background but this happens.

    Code (csharp):
    1. -> applicationWillEnterForeground()
    2. -> applicationDidBecomeActive()
    3. System.IO.IOException: Read failure ---> System.Net.Sockets.SocketException: The descriptor is not a socket
    4.   at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
    5.   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    6.   --- End of inner exception stack trace ---
    7.   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
    8.   at System.IO.Stream.ReadByte () [0x00000] in <filename unknown>:0
    9.   at HTTP.Response.ReadLine (System.IO.Stream stream) [0x00000] in <filename unknown>:0
    10.   at HTTP.Response.ReadFromStream (System.IO.Stream inputStream) [0x00000] in <filename unknown>:0
    11.   at HTTP.Request.<Send>m__53 (System.Object t) [0x00000] in <filename unknown>:0
     
  21. jogo

    jogo

    Joined:
    May 31, 2013
    Posts:
    17
    Is there an error in the latest Uniweb update? I am trying to connect to a server that redirects me twice. Just a few minutes ago everything was fine. Then I updated Uniweb and now I receive a http status error 400: "The request sent by the client was syntactically incorrect." Nothing except the update had changed on my project...
    I am using Unity 4.2.2f
     
  22. dave_mm0

    dave_mm0

    Joined:
    Feb 8, 2013
    Posts:
    26
    None of my http requests work after the app has gone into the background. Is there any fix for this?
     
  23. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I am currently resolving this and some of the other reported bugs.
     
  24. dave_mm0

    dave_mm0

    Joined:
    Feb 8, 2013
    Posts:
    26
    Awesome thanks.
     
  25. gdagley

    gdagley

    Joined:
    Jul 29, 2013
    Posts:
    6
    I just ran into an issue with special characters in my response showing up as question marks, e.g. 'abc????' instead of 'abc企业日益' When I changed the following it started working, but I wanted to make sure I wasn't missing something else important here.

    In Response.cs:

    Code (csharp):
    1.  
    2.         public string Text {
    3.             get {
    4. //              return System.Text.Encoding.Default.GetString(Bytes);
    5.                 return System.Text.UnicodeEncoding.UTF8.GetString(Bytes);
    6.             }
    7.         }
    8.  
     
  26. dragon376

    dragon376

    Joined:
    Mar 2, 2013
    Posts:
    9
    Does Uniweb uses System.Net.Sockets? Meaning does Uniweb work on Unity IOS Basic or do I need to have pro to use it?
     
  27. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    yes, no, yes
     
  28. Fragmental

    Fragmental

    Joined:
    Jun 30, 2013
    Posts:
    61
    I'm currently using version 4.2.0f4. Is it safe to upgrade to 4.3.0 without breaking anything in uniweb?

    edit: this is in response to uniweb breaking 3.5.7...I didn't read the comment very well.
     
    Last edited: Nov 22, 2013
  29. PfcGarcia

    PfcGarcia

    Joined:
    Aug 27, 2013
    Posts:
    17
    Hi Simon,

    Can UniWeb HTTP be used to connect to default 80 HTTP port in Web Player with PrefetchSocketPolicy invoked on non-843 port? Have you or someone tested such setup? It's not working currently, at least for me.

    I can't even get Sockets working with privileged ports, here is my question on Unity Answers, maybe you can advise something here.
     
  30. BestHTTP

    BestHTTP

    Joined:
    Sep 11, 2013
    Posts:
    1,664
    Hi PfcGarcia,

    Have you invoked manually the Security.PrefetchSocketPolicy before you try to connect (as in the docs)?
    In the sockpol.exe's logs there are any entry that a client connected to it?

    If you use it as mentioned in the docs and doesn't working, than i think you should fill a bugreport.
     
  31. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Hi PfcGarcia, I've written a post to help get people setup correctly with the whole crossdomain thing.

    http://entitycrisis.blogspot.com.au/2012/09/uniweb-www-and-crossdomainxml-explained.html

    If you still run into trouble please let me know.

    -Sw.
     
    Last edited: Nov 21, 2013
  32. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    What happened to SetHeader and GetHeader?

    My latest project won't build now due to:

    Assets/Scripts/xx(233,48): error CS1061: Type `HTTP.Response' does not contain a definition for `GetHeader' and no extension method `GetHeader' of type `HTTP.Response' could be found (are you missing a using directive or an assembly reference?)
    Assets/Scripts/xx(262,33): error CS1061: Type `HTTP.Request' does not contain a definition for `SetHeader' and no extension method `SetHeader' of type `HTTP.Request' could be found (are you missing a using directive or an assembly reference?)

    ty!
     
  33. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    These methods have been marked as obsolete for some months. The new version has removed all methods previously marked as obsolete. You can now use response.header.Get / Add and response.request.headers.Get / Add for the same functionality.
     
  34. jmoffetiv

    jmoffetiv

    Joined:
    Nov 22, 2013
    Posts:
    1
    Where can i view the license for UniWeb and can I get an evaluation license?
     
  35. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Just send me an email, simon@differentmethods.com. The license is just the standard asset store license.
     
    Last edited: Nov 23, 2013
  36. PfcGarcia

    PfcGarcia

    Joined:
    Aug 27, 2013
    Posts:
    17
    PrefetchSocketPolicy can be invoked only on the same port privilege type (priv, nonpriv) as the port you are going to use. Here is the response from support:
    "Unity is hard coded to connect to the socket policy server on port 843. If your server runs on any other port, you need to call PrefetchSocketPolicy. If the server runs on a port above 1024, then only ports above 1024 can be used. So, your problem is that your server runs on 10843, but you are then trying to make a socket connection on port 777. Since this port is below 1024, and your policy was served from above 1024 the connection is blocked."
     
  37. PfcGarcia

    PfcGarcia

    Joined:
    Aug 27, 2013
    Posts:
    17
    Hi Simon,

    Looks live I've found an issue with UniWeb version 2 working with gzipped response. In Response.cs there is a code at line 224 trying to SetLength of MemoryStream to 0, but corresponding Mono function throws exception "The object was used after being disposed.":

    at System.IO.MemoryStream.CheckIfClosedThrowDisposed () [0x0000b] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/MemoryStream.cs:135
    at System.IO.MemoryStream.SetLength (Int64 value) [0x00023] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/MemoryStream.cs:339
    at HTTP.Response.ProcessReceivedBytes () [0x000d4] in C:\Users\dmitryg\Documents\Sandbox\Assets\UniWeb\Plugins\Response.cs:225
    at HTTP.Response.ReadFromStream (System.IO.Stream inputStream) [0x00124] in C:\Users\dmitryg\Documents\Sandbox\Assets\UniWeb\Plugins\Response.cs:200
    at HTTP.Request.<BeginSending>m__52 (System.Object t) [0x0005e] in C:\Users\dmitryg\Documents\Sandbox\Assets\UniWeb\Plugins\Request.cs:191

    I've added if(output.CanRead) before that string and it worked fine but it looks like there are more similar places in the code so I'll leave it to you :)

    Thanks.
     
  38. jogo

    jogo

    Joined:
    May 31, 2013
    Posts:
    17
    Hello Simon,

    in the new update, HTTP.Request.OnDirect has been deleted, it seems to be handled by Uniweb automatically - so I deleted the lines that handled the redirect ... but it does not work as before... am I missing something? In my doRedirect()-Method the redirect had to be a "GET" while the standard call was a "POST".

    Code (csharp):
    1.         var r = new HTTP.Request("POST", server + "/" + url, b);
    2.         r.headers.Set("Content-Type", "text/plain");
    3.         r.headers.Set("Accept", "application/json");
    4.         // not used anymore:
    5.         //r.OnRedirect = delegate (Uri uri){
    6.         //  response = doRedirect(uri);        
    7.         //};
    8.         r.Send();
    9.         while(!r.isDone) { }
    10.  
    11.  
    12. ... the old doRedirect():
    13.  
    14.     private HTTP.Response doRedirect(Uri redirectUri) {
    15.         var redirect = new HTTP.Request("GET", redirectUri.AbsoluteUri);
    16.         HTTP.Response response = null;
    17.         redirect.OnRedirect = delegate(Uri uri) {
    18.             response = doRedirect(uri);
    19.         };
    20.         redirect.Send();
    21.         while(!redirect.isDone) {}
    22.         if (response == null) {
    23.             response = redirect.response;
    24.         }
    25.         return response;
    26.     }
     
  39. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    This is now fixed.
     
  40. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Thanks for the bug report, this is now fixed in 2.1.1 and available in the Asset Store.
     
  41. Ciprian

    Ciprian

    Joined:
    Jul 9, 2013
    Posts:
    27
    Hi Simon.. cool plugin..

    I do have some questions... how do I execute PUT and DELETE requests.. also, for POST request do I need to use the WWWPost method?

    Do you have any more examples than the one included with the packaged? Haven't seen the JsonDeserialiser in the examples..

    will the HTTP class work with oauth2.0?
     
  42. Curyous

    Curyous

    Joined:
    Apr 11, 2012
    Posts:
    3
    Hi Simon,

    I had make the following small change to make UniWeb work for me when doing a PUT, please include this in the next revision:

    Request.cs:248, changed:
    Code (csharp):
    1. if (uri.UserInfo != null) {
    to:
    Code (csharp):
    1. if (uri.UserInfo != null  uri.UserInfo.Length > 0) {
     
  43. jogo

    jogo

    Joined:
    May 31, 2013
    Posts:
    17
    Hello Simon,

    I get a SocketException with HTTP.Request on iOS 7, but only if the iPad once had a connection, then the iPad was switched off and is then again switched on. And I don't get the Update 2.1.1 you mentioned a few posts above in Asset Store, the latest version there is 2.1..

    Code (csharp):
    1. System.Net.Sockets.SocketException: Invalid arguments
    2.   at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue) [0x00000] in <filename unknown>:0
    3.   at System.Net.Sockets.TcpClient.set_ReceiveTimeout (Int32 value) [0x00000] in <filename unknown>:0
    4.   at HTTP.ActiveConnection.get_Connected () [0x00000] in <filename unknown>:0
    5.   at HTTP.Request.GetClient (System.String host, Int32 port, Boolean useSsl) [0x00000] in <filename unknown>:0
    6.   at HTTP.Request.<Send>m__5 (System.Object t) [0x00000] in <filename unknown>:0
    7.  
    8.  
    9.  
    10.         // the calling code - not working anymore after switching off iPad:
    11.         var r = new HTTP.Request("POST", url, b);
    12.         r.headers.Set("Content-Type", "text/plain");
    13.         r.headers.Set("Accept", "application/json");
    14.         r.OnRedirect = delegate (Uri uri){
    15.             response = doRedirect(uri);        
    16.         };
    17.         r.Send();
    18.         while(!r.isDone) { }
    19.  
     
  44. jogo

    jogo

    Joined:
    May 31, 2013
    Posts:
    17
    Hello Simon,

    I see the error above (Problem with iOS waking up) should be fixed in Uniweb 2.1.2. Great, thanks for that! Unfortunately I am not able to use it, because there still seems to be something wrong with the redirects. A first redirect to an OAuth script works, but coming back from there, the handling of the next redirect leads to an error 400 - bad request.


    Edit:
    Problem solved!!!
    deleting the comment in the line

    //#define USE_COOKIES

    in request.cs did it!
     
    Last edited: Dec 3, 2013
  45. jogo

    jogo

    Joined:
    May 31, 2013
    Posts:
    17
    Is it possible to validate a ssl certificate on iOS and Android? Or if not: will it be in the future?
    There is a method ValidateServerCertificate() in Request.cs, but I don't know how to use it.
    The Debug.LogWarning() prints the same text for a valid and an invalid certificate:
    SSL Cert Error:RemoteCertificateNotAvailable, RemoteCertificateChainErrors
     
  46. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    This is on the mediumj term TODO list. The method you discovered is where the future implementation will go, or your own implementation if you choose.
     
  47. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    That's actually what I was interested in UniWeb for, Unity's WWW class doesn't seem to support self-signed certificates for HTTPS under Android, so I was hoping I could use Uniweb for that. So Uniweb doesn't support it either, will the .net ServerCertificateValidationCallback work with Uniweb?

    Also, I read somewhere that you needed the full .Net 2.0 for Uniweb instead of the Subset. Is this true?
     
    Last edited: Dec 4, 2013
  48. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    The .NET SSL support should work with UniWeb. I'll look into this further.

    Full .NET is currently required if you have GZip enabled. I'm also looking into removing this requirement.
     
  49. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I've just pushed up version 2.1.3 which removes the requirement to use full .NET 2.0 on iOS, and has some comments in Request.cs:line 108 where custom SSL certificate validation can be added, if needed using the ServerCertificateValidationCallback.
     
  50. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Thanks, Uniweb works great! Very similar API to WWW, except better. Can't use the Micro mscorlib with it on iOS, but just dropping that down one level to Strip ByteCode and adding System.Security.Cryptography to link.xml does the trick.