@@ -66,8 +66,7 @@ public RestClient()
66
66
/// Sets the BaseUrl property for requests made by this client instance
67
67
/// </summary>
68
68
/// <param name="baseUrl"></param>
69
- public RestClient ( string baseUrl )
70
- : this ( )
69
+ public RestClient ( string baseUrl ) : this ( )
71
70
{
72
71
BaseUrl = baseUrl ;
73
72
}
@@ -130,6 +129,9 @@ public void ClearHandlers()
130
129
/// <returns>IDeserializer instance</returns>
131
130
private IDeserializer GetHandler ( string contentType )
132
131
{
132
+ if ( contentType == null )
133
+ throw new ArgumentNullException ( "contentType" ) ;
134
+
133
135
if ( string . IsNullOrEmpty ( contentType ) && ContentHandlers . ContainsKey ( "*" ) )
134
136
{
135
137
return ContentHandlers [ "*" ] ;
@@ -391,7 +393,7 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
391
393
select new HttpHeader
392
394
{
393
395
Name = p . Name ,
394
- Value = p . Value . ToString ( )
396
+ Value = Convert . ToString ( p . Value )
395
397
} ;
396
398
397
399
foreach ( var header in headers )
@@ -404,7 +406,7 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
404
406
select new HttpCookie
405
407
{
406
408
Name = p . Name ,
407
- Value = p . Value . ToString ( )
409
+ Value = Convert . ToString ( p . Value )
408
410
} ;
409
411
410
412
foreach ( var cookie in cookies )
@@ -418,7 +420,7 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
418
420
select new HttpParameter
419
421
{
420
422
Name = p . Name ,
421
- Value = p . Value . ToString ( )
423
+ Value = Convert . ToString ( p . Value )
422
424
} ;
423
425
424
426
foreach ( var parameter in @params )
@@ -451,17 +453,18 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
451
453
if ( ! http . Files . Any ( ) )
452
454
{
453
455
object val = body . Value ;
456
+
454
457
if ( val is byte [ ] )
455
458
http . RequestBodyBytes = ( byte [ ] ) val ;
456
459
else
457
- http . RequestBody = body . Value . ToString ( ) ;
460
+ http . RequestBody = Convert . ToString ( body . Value ) ;
458
461
}
459
462
else
460
463
{
461
464
http . Parameters . Add ( new HttpParameter
462
465
{
463
466
Name = body . Name ,
464
- Value = body . Value . ToString ( )
467
+ Value = Convert . ToString ( body . Value )
465
468
} ) ;
466
469
}
467
470
}
@@ -482,20 +485,22 @@ private void ConfigureProxy(IHttp http)
482
485
483
486
private RestResponse ConvertToRestResponse ( IRestRequest request , HttpResponse httpResponse )
484
487
{
485
- var restResponse = new RestResponse ( ) ;
486
- restResponse . Content = httpResponse . Content ;
487
- restResponse . ContentEncoding = httpResponse . ContentEncoding ;
488
- restResponse . ContentLength = httpResponse . ContentLength ;
489
- restResponse . ContentType = httpResponse . ContentType ;
490
- restResponse . ErrorException = httpResponse . ErrorException ;
491
- restResponse . ErrorMessage = httpResponse . ErrorMessage ;
492
- restResponse . RawBytes = httpResponse . RawBytes ;
493
- restResponse . ResponseStatus = httpResponse . ResponseStatus ;
494
- restResponse . ResponseUri = httpResponse . ResponseUri ;
495
- restResponse . Server = httpResponse . Server ;
496
- restResponse . StatusCode = httpResponse . StatusCode ;
497
- restResponse . StatusDescription = httpResponse . StatusDescription ;
498
- restResponse . Request = request ;
488
+ var restResponse = new RestResponse
489
+ {
490
+ Content = httpResponse . Content ,
491
+ ContentEncoding = httpResponse . ContentEncoding ,
492
+ ContentLength = httpResponse . ContentLength ,
493
+ ContentType = httpResponse . ContentType ,
494
+ ErrorException = httpResponse . ErrorException ,
495
+ ErrorMessage = httpResponse . ErrorMessage ,
496
+ RawBytes = httpResponse . RawBytes ,
497
+ ResponseStatus = httpResponse . ResponseStatus ,
498
+ ResponseUri = httpResponse . ResponseUri ,
499
+ Server = httpResponse . Server ,
500
+ StatusCode = httpResponse . StatusCode ,
501
+ StatusDescription = httpResponse . StatusDescription ,
502
+ Request = request
503
+ } ;
499
504
500
505
foreach ( var header in httpResponse . Headers )
501
506
{
@@ -547,6 +552,7 @@ private IRestResponse<T> Deserialize<T>(IRestRequest request, IRestResponse raw)
547
552
if ( response . ErrorException == null )
548
553
{
549
554
IDeserializer handler = GetHandler ( raw . ContentType ) ;
555
+
550
556
// Only continue if there is a handler defined else there is no way to deserialize the data.
551
557
// This can happen when a request returns for example a 404 page instead of the requested JSON/XML resource
552
558
if ( handler != null )
0 commit comments