diff --git a/lib/JSON.cs b/lib/JSON.cs index ae06abd..ea014eb 100644 --- a/lib/JSON.cs +++ b/lib/JSON.cs @@ -273,24 +273,24 @@ protected static object ParseNumber (char[] json, ref int index, ref bool succes var token = new string (json, index, charLength); index = lastIndex + 1; - if ( token.Contains( "." ) ) + if ( token.Contains( "." ) || ((token.Contains("e") || token.Contains("E")) && !token.StartsWith("0x"))) { float number; success = float.TryParse (token, NumberStyles.Any, CultureInfo.InvariantCulture, out number); return number; } - else if(token.Length <= 10) - { - int number; - success = int.TryParse(token, out number); - return number; - } else { - long number; - success = long.TryParse(token, out number); - return number; - } + int number32; + success = int.TryParse(token, out number32); + if (success) { + return number32; + } + + long number64; + success = long.TryParse(token, out number64); + return number64; + } } protected static int GetLastIndexOfNumber (char[] json, int index) diff --git a/src/Request.cs b/src/Request.cs index 2d86473..aab7299 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -74,30 +74,20 @@ public Request (string method, string uri, byte[] bytes) this.byteStream = new MemoryStream(bytes); } - public Request(string method, string uri, StreamedWWWForm form){ - this.method = method; - this.uri = new Uri (uri); - this.byteStream = form.stream; - foreach ( DictionaryEntry entry in form.headers ) - { - this.AddHeader( (string)entry.Key, (string)entry.Value ); - } - } - public Request( string method, string uri, WWWForm form ) { this.method = method; this.uri = new Uri (uri); this.byteStream = new MemoryStream(form.data); -#if UNITY_5 - foreach ( var entry in form.headers ) +#if UNITY_4 + foreach ( DictionaryEntry entry in form.headers ) { - this.AddHeader( entry.Key, entry.Value ); + this.AddHeader( (string)entry.Key, (string)entry.Value ); } #else - foreach ( DictionaryEntry entry in form.headers ) + foreach (var entry in form.headers) { - this.AddHeader( (string)entry.Key, (string)entry.Value ); + this.AddHeader(entry.Key, entry.Value); } #endif } diff --git a/src/StreamedWWWForm.cs b/src/StreamedWWWForm.cs deleted file mode 100644 index 0510e48..0000000 --- a/src/StreamedWWWForm.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Collections; - -namespace UnityHTTP -{ - public class StreamedWWWForm { - string boundary; - public FormDataStream stream; - - public Hashtable headers { - get { - return new Hashtable { - { "Content-Type", "multipart/form-data; boundary=\"" + boundary + "\""} - }; - } - } - - public StreamedWWWForm(){ - byte[] bytes = new byte[40]; - var random = new Random(); - for (int i=0; i<40; i++){ - bytes[i] = (byte)(48 + random.Next(62)); - if (bytes[i] > 57){ - bytes[i] += 7; - } - if (bytes[i] > 90){ - bytes[i] += 6; - } - } - boundary = Encoding.ASCII.GetString(bytes); - stream = new FormDataStream(boundary); - } - - public void AddField(string fieldName, string fieldValue){ - var contentStream = new MemoryStream(Encoding.UTF8.GetBytes(fieldValue)); - stream.AddPart(fieldName, "text/plain; charset=\"utf-8\"", contentStream); - - } - public void AddBinaryData(string fieldName, byte[] contents=null, string mimeType = null){ - var contentStream = new MemoryStream(contents); - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - stream.AddPart(fieldName, mimeType, contentStream, fieldName + ".dat"); - } - public void AddBinaryData(string fieldName, Stream contents=null, string mimeType = null){ - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - stream.AddPart(fieldName, mimeType, contents, fieldName + ".dat"); - } - public void AddFile(string fieldName, string path, string mimeType=null){ - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - var contents = new FileInfo(path).Open(FileMode.Open); - stream.AddPart(fieldName, mimeType, contents, fieldName + ".dat"); - } - } -}