예제 #1
0
 private R Send <T, R>(HttpMethod method, string uri, GenericOptions options, T obj, string contentType)
 {
     using (var ms = new MemoryStream())
     {
         JsonSerializer.WriteObject(ms, obj);
         ms.Position = 0;
         using (var v = SendRaw(method, BuildUri(uri, options), ms, contentType))
         {
             return(JsonSerializer.ReadObject <R>(v));
         }
     }
 }
예제 #2
0
        public Uri BuildUri(string uri, GenericOptions option)
        {
            var ub = new UriBuilder(uri);

            if (option != null)
            {
                var query = HttpUtility.ParseQueryString(ub.Query);
                foreach (var pair in option.ToQueryList())
                {
                    if (pair.Value != null)
                    {
                        query[pair.Key] = pair.Value + "";
                    }
                }
                ub.Query = query.ToString();
            }
            return(ub.Uri);
        }
예제 #3
0
 public T Get <T>(string uri, IEnumerable <Type> knownTypes, GenericOptions options = null)
 {
     using (var s = GetRaw(uri, options)) return(JsonSerializer.ReadObject <T>(s, knownTypes));
 }
예제 #4
0
 public T Get <T>(string uri, GenericOptions options = null)
 {
     using (var s = GetRaw(uri, options)) return(JsonSerializer.ReadObject <T>(s));
 }
예제 #5
0
 public Stream PostRaw(string uri, Stream content, GenericOptions options = null, string contentType = null)
 {
     using (content) return(SendRaw(HttpMethod.POST, BuildUri(uri, options), content, contentType));
 }
예제 #6
0
 public void Delete(string uri, GenericOptions options = null)
 {
     SendRaw(HttpMethod.DELETE, BuildUri(uri, options));
 }
예제 #7
0
 public string GetString(string uri, GenericOptions options = null)
 {
     return(SendRaw(HttpMethod.GET, BuildUri(uri, options)).ReadToEnd().GetString());
 }
예제 #8
0
 public Stream GetRaw(string uri, GenericOptions options = null)
 {
     return(SendRaw(HttpMethod.GET, BuildUri(uri, options)));
 }
예제 #9
0
 public T Post <T>(string uri, Stream stream, string mimeType, GenericOptions options = null)
 {
     return(JsonSerializer.ReadObject <T>(PostRaw(uri, stream, options, mimeType)));
 }
예제 #10
0
 public T Post <T>(string uri, T obj, IDictionary <Stream, string> otherParts = null, GenericOptions options = null, string contentType = null)
 {
     return(Post <T, T>(uri, obj, otherParts, options, contentType));
 }
예제 #11
0
 public R Post <T, R>(string uri, T obj, IDictionary <Stream, string> otherParts = null, GenericOptions options = null, string contentType = null)
 {
     if (otherParts == null)
     {
         return(Send <T, R>(HttpMethod.POST, uri, options, obj, contentType));
     }
     using (var ms = new MemoryStream())
     {
         JsonSerializer.WriteObject(ms, obj);
         ms.Position = 0;
         return(JsonSerializer.ReadObject <R>(Post(BuildUri(uri, options), ms, otherParts, contentType)));
     }
 }
예제 #12
0
 public R Put <T, R>(string uri, T obj, GenericOptions options = null, string contentType = null)
 {
     return(Send <T, R>(HttpMethod.PUT, uri, options, obj, contentType));
 }