Exemple #1
0
    /*
     * Send Obj via Post Http request
     */
    public string SendObjHttpRequestMsg(long ID, dynamic MyObj)
    {
        var body    = GenericJsonSerializer.Serialize(MyObj);
        var request = new HttpRequestMessage
        {
            RequestUri = new Uri("My URL"),
            Method     = HttpMethod.Post,
            Content    = new StringContent(body) // If byte[] new ByteArrayContent(Data)
        };

        request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        request.Headers.Add("Authorization", "Bearer " + token);
        HttpResponseMessage response = null;
        string responseString        = null;

        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            response = client.SendAsync(request).Result;
        }
        if (!response.IsSuccessStatusCode)
        {
            var errorResult = response.Content.ReadAsStringAsync();
            if (errorResult != null)
            {
                throw new Exception(errorResult);
            }
        }
        responseString = response.Content.ReadAsStringAsync();
        return(responseString);
    }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SalesforceClient"/> class.
 /// </summary>
 /// <param name="restClient">The rest client.</param>
 protected internal SalesforceClient(IRestClient restClient)
 {
     m_restClient            = restClient;
     ApiVersion              = "v28.0";
     m_deserializer          = new DynamicJsonDeserializer();
     genericJsonDeserializer = new GenericJsonDeserializer(new SalesforceContractResolver(false));
     updateJsonSerializer    = new GenericJsonSerializer(new SalesforceContractResolver(true));
 }
Exemple #3
0
        public IEnumerable <StoreInfo> Download(ZipCode zipCode)
        {
            var url          = _zipCodeUrlSerializer.ToUrl(zipCode);
            var responseJson = _urlDownloader.Download(url);

            var json = responseJson
                       .TrimStart('(')
                       .TrimEnd(')');

            return(GenericJsonSerializer.FromJson <StoresLocatorResponse>(json)
                   .ResultData
                   .Select(StoreInfo.Create)
                   .ToArray());
        }