Exemple #1
0
        // token received from CreateSession/RenewSession API call
        public GetImageDownloadAuthorizationsResponse AuthorizeDownload(string token, IList <ImageSize> imageSizes)
        {
            var getImageDownloadAuthorizationsRequest = new GetImageDownloadAuthorizationsRequest
            {
                RequestHeader = new RequestHeader {
                    Token = token
                },
                GetImageDownloadAuthorizationsRequestBody = new GetImageDownloadAuthorizationsRequestBody
                {
                    ImageSizes = imageSizes
                }
            };

            return(MakeWebRequest(GetImageDownloadAuthorizationsRequestUrl, getImageDownloadAuthorizationsRequest));
        }
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static GetImageDownloadAuthorizationsResponse MakeWebRequest(string requestUrl, GetImageDownloadAuthorizationsRequest 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<GetImageDownloadAuthorizationsResponse>(jsonResult);
        }
        // token received from CreateSession/RenewSession API call
        public GetImageDownloadAuthorizationsResponse AuthorizeDownload(string token, IList<ImageSize> imageSizes)
        {
            var getImageDownloadAuthorizationsRequest = new GetImageDownloadAuthorizationsRequest
            {
                RequestHeader = new RequestHeader { Token = token },
                GetImageDownloadAuthorizationsRequestBody = new GetImageDownloadAuthorizationsRequestBody
                                                                {
                                                                    ImageSizes = imageSizes
                                                                }
            };

            return MakeWebRequest(GetImageDownloadAuthorizationsRequestUrl, getImageDownloadAuthorizationsRequest);
        }
Exemple #4
0
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static GetImageDownloadAuthorizationsResponse MakeWebRequest(string requestUrl, GetImageDownloadAuthorizationsRequest 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 <GetImageDownloadAuthorizationsResponse>(jsonResult));
        }