Example #1
0
        // token received from CreateSession/RenewSession API call
        public GetLargestImageDownloadAuthorizationsResponse GetLargestDownloadForImages(string token, List <Image> imageIds)
        {
            var getLargestImageDownloadAuthorizationsRequest = new GetLargestImageDownloadAuthorizationsRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                GetLargestImageDownloadAuthorizationsRequestBody = new GetLargestImageDownloadAuthorizationsRequestBody
                {
                    Images = imageIds
                }
            };

            return(MakeWebRequest(Constants.GetLargestImageDownloadAuthorizationsRequestUrl, getLargestImageDownloadAuthorizationsRequest));
        }
Example #2
0
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static GetLargestImageDownloadAuthorizationsResponse MakeWebRequest(string requestUrl, GetLargestImageDownloadAuthorizationsRequest request)
        {
            var webRequest = WebRequest.Create(requestUrl) as HttpWebRequest;

            webRequest.Method      = "POST";
            webRequest.ContentType = "application/json";

            var jsonSerializer = new JavaScriptSerializer();
            var requestStr     = jsonSerializer.Serialize(request);

            Debug.WriteLine(requestStr);

            using (var writer = new StreamWriter(webRequest.GetRequestStream()))
            {
                writer.Write(requestStr);
                writer.Close();
            }

            var response = webRequest.GetResponse() as HttpWebResponse;

            string jsonResult;

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                jsonResult = reader.ReadToEnd();
                reader.Close();
            }

            Debug.WriteLine(jsonResult);

            return(jsonSerializer.Deserialize <GetLargestImageDownloadAuthorizationsResponse>(jsonResult));
        }