/// <summary> /// Download string but with Json /// </summary> /// <typeparam name="T">The type to deserialize the response into</typeparam> /// <param name="url">The url to download</param> /// <param name="downloadSerializerSettings">The serializer settings to use when deserializing the response</param> /// <returns>The deserialized response</returns> public virtual T DownloadJson <T>(Uri url, JsonSerializerSettings downloadSerializerSettings = null) { this.Headers[HttpRequestHeader.Accept] = this.JsonAcceptContentType; this.PreRequest(url); return(JsonConvert.DeserializeObject <T>(this.DownloadString(url), downloadSerializerSettings ?? this.DefaultSettings)); }
/// <summary> /// Upload string, but with Json /// </summary> /// <param name="url">The url to post to</param> /// <param name="toUpload">The pre-serialized object to upload</param> /// <param name="uploadSerializerSettings">The settings to use when serializing the uploaded object</param> /// <returns>The string response from the server</returns> public virtual string UploadJson(Uri url, object toUpload, JsonSerializerSettings uploadSerializerSettings = null) { this.Headers[HttpRequestHeader.ContentType] = this.JsonContentType; this.Headers[HttpRequestHeader.Accept] = this.JsonAcceptContentType; this.PreRequest(url); return(this.UploadString(url, JsonConvert.SerializeObject(toUpload, uploadSerializerSettings ?? this.DefaultSettings))); }
/// <summary> /// Upload string, but with Json /// </summary> /// <typeparam name="T">the type to deserialize the response to</typeparam> /// <param name="url">The url to post to</param> /// <param name="toUpload">The pre-serialized object to upload</param> /// <param name="downloadSerializerSettings">The settings to use when deserializing the response</param> /// <param name="uploadSerializerSettings">The settings to use when serializing the request</param> /// <returns>The response, deserialized</returns> public virtual T UploadJson <T>(Uri url, object toUpload, JsonSerializerSettings downloadSerializerSettings = null, JsonSerializerSettings uploadSerializerSettings = null) { string postBody = ""; if (!(toUpload is null)) { postBody = JsonConvert.SerializeObject(toUpload, uploadSerializerSettings ?? this.DefaultSettings); } this.Headers[HttpRequestHeader.Accept] = this.JsonAcceptContentType; this.Headers[HttpRequestHeader.ContentType] = this.JsonContentType; this.PreRequest(url); string response = this.UploadString(url, postBody); return(JsonConvert.DeserializeObject <T>(response, downloadSerializerSettings ?? this.DefaultSettings)); }
/// <summary> /// Posts the provided body and downloads the Uri as a string /// </summary> /// <param name="address">The Uri to download</param> /// <param name="body">The content to post in the body</param> /// <returns>The response as a string</returns> public virtual TReturn UploadString <TReturn>(Uri address, string body) { this.PreRequest(address); return(JsonConvert.DeserializeObject <TReturn>(base.UploadString(address, body))); }