26
26
using System . Text ;
27
27
using UnityEngine ;
28
28
using UnityEngine . Networking ;
29
+ using FullSerializer ;
29
30
30
31
#if ! NETFX_CORE
31
32
using System . Net ;
@@ -233,6 +234,10 @@ public Request()
233
234
/// The data to send through the connection. Do not use Forms if set.
234
235
/// </summary>
235
236
public byte [ ] Send { get ; set ; }
237
+ ///// <summary>
238
+ ///// The data to send through the connection. Do not use Forms if set.
239
+ ///// </summary>
240
+ //public string Body { get; set; }
236
241
/// <summary>
237
242
/// Multi-part form data that needs to be sent. Do not use Send if set.
238
243
/// </summary>
@@ -414,9 +419,9 @@ private IEnumerator ProcessRequestQueue()
414
419
Response resp = new Response ( ) ;
415
420
416
421
DateTime startTime = DateTime . Now ;
417
- if ( string . IsNullOrEmpty ( req . HttpMethod ) )
422
+ if ( string . IsNullOrEmpty ( req . HttpMethod ) || req . Delete )
418
423
{
419
- WWW www = null ;
424
+ UnityWebRequest www = null ;
420
425
if ( req . Forms != null )
421
426
{
422
427
if ( req . Send != null )
@@ -443,13 +448,30 @@ private IEnumerator ProcessRequestQueue()
443
448
{
444
449
Log . Error ( "RESTConnector.ProcessRequestQueue()" , "Exception when initializing WWWForm: {0}" , e . ToString ( ) ) ;
445
450
}
446
- www = new WWW ( url , form . data , req . Headers ) ;
451
+ www = UnityWebRequest . Post ( url , form ) ;
447
452
}
448
453
else if ( req . Send == null )
449
- www = new WWW ( url , null , req . Headers ) ;
454
+ {
455
+ www = UnityWebRequest . Get ( url ) ;
456
+ }
450
457
else
451
- www = new WWW ( url , req . Send , req . Headers ) ;
458
+ {
459
+ www = new UnityWebRequest ( url , UnityWebRequest . kHttpVerbPOST ) ;
460
+ www . uploadHandler = ( UploadHandler ) new UploadHandlerRaw ( req . Send ) ;
461
+ www . SetRequestHeader ( "Content-Type" , "application/json" ) ;
462
+ }
463
+
464
+ foreach ( KeyValuePair < string , string > kvp in req . Headers )
465
+ {
466
+ www . SetRequestHeader ( kvp . Key , kvp . Value ) ;
467
+ }
468
+ www . downloadHandler = new DownloadHandlerBuffer ( ) ;
452
469
470
+ #if UNITY_2017_2_OR_NEWER
471
+ www . SendWebRequest ( ) ;
472
+ #else
473
+ www . Send ( ) ;
474
+ #endif
453
475
#if ENABLE_DEBUGGING
454
476
Log . Debug ( "RESTConnector" , "URL: {0}" , url ) ;
455
477
#endif
@@ -465,7 +487,7 @@ private IEnumerator ProcessRequestQueue()
465
487
if ( req . OnUploadProgress != null )
466
488
req . OnUploadProgress ( www . uploadProgress ) ;
467
489
if ( req . OnDownloadProgress != null )
468
- req . OnDownloadProgress ( www . progress ) ;
490
+ req . OnDownloadProgress ( www . downloadProgress ) ;
469
491
470
492
#if UNITY_EDITOR
471
493
if ( ! UnityEditorInternal . InternalEditorUtility . inBatchMode )
@@ -508,16 +530,16 @@ private IEnumerator ProcessRequestQueue()
508
530
URL = url ,
509
531
ErrorCode = resp . HttpResponseCode = nErrorCode ,
510
532
ErrorMessage = www . error ,
511
- Response = www . text ,
512
- ResponseHeaders = www . responseHeaders
533
+ Response = www . downloadHandler . text ,
534
+ ResponseHeaders = www . GetResponseHeaders ( )
513
535
} ;
514
536
515
537
if ( bError )
516
538
Log . Error ( "RESTConnector.ProcessRequestQueue()" , "URL: {0}, ErrorCode: {1}, Error: {2}, Response: {3}" , url , nErrorCode , www . error ,
517
- string . IsNullOrEmpty ( www . text ) ? "" : www . text ) ;
539
+ string . IsNullOrEmpty ( www . downloadHandler . text ) ? "" : www . downloadHandler . text ) ;
518
540
else
519
541
Log . Warning ( "RESTConnector.ProcessRequestQueue()" , "URL: {0}, ErrorCode: {1}, Error: {2}, Response: {3}" , url , nErrorCode , www . error ,
520
- string . IsNullOrEmpty ( www . text ) ? "" : www . text ) ;
542
+ string . IsNullOrEmpty ( www . downloadHandler . text ) ? "" : www . downloadHandler . text ) ;
521
543
}
522
544
if ( ! www . isDone )
523
545
{
@@ -535,16 +557,16 @@ private IEnumerator ProcessRequestQueue()
535
557
if ( ! bError )
536
558
{
537
559
resp . Success = true ;
538
- resp . Data = www . bytes ;
539
- resp . HttpResponseCode = GetResponseCode ( www ) ;
560
+ resp . Data = www . downloadHandler . data ;
561
+ resp . HttpResponseCode = www . responseCode ;
540
562
}
541
563
else
542
564
{
543
565
resp . Success = false ;
544
566
resp . Error = error ;
545
567
}
546
568
547
- resp . Headers = www . responseHeaders ;
569
+ resp . Headers = www . GetResponseHeaders ( ) ;
548
570
549
571
resp . ElapsedTime = ( float ) ( DateTime . Now - startTime ) . TotalSeconds ;
550
572
0 commit comments