コード例 #1
0
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static CreateDownloadResponse MakeWebRequest(string requestUrl, CreateDownloadRequest 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 <CreateDownloadResponse>(jsonResult));
        }
コード例 #2
0
        // securetoken received from CreateSession/RenewSession API call
        public CreateDownloadResponse CreateRequest(string secureToken, List<DownloadItem> downloadTokens)
        {
            var createDownloadRequest = new CreateDownloadRequest
            {
                RequestHeader = new RequestHeader { Token = secureToken },
                CreateDownloadRequestBody = new CreateDownloadRequestBody
                {
                    DownloadItems = downloadTokens
                }
            };

            return MakeWebRequest(CreateDownloadRequestRequestUrl, createDownloadRequest);
        }
コード例 #3
0
        // securetoken received from CreateSession/RenewSession API call
        public CreateDownloadResponse CreateRequest(string secureToken, List <DownloadItem> downloadTokens)
        {
            var createDownloadRequest = new CreateDownloadRequest
            {
                RequestHeader = new RequestHeader {
                    Token = secureToken
                },
                CreateDownloadRequestBody = new CreateDownloadRequestBody
                {
                    DownloadItems = downloadTokens
                }
            };

            return(MakeWebRequest(CreateDownloadRequestRequestUrl, createDownloadRequest));
        }
コード例 #4
0
        //You may wish to replace this code with your preferred library for posting and receiving JSON data.
        private static CreateDownloadResponse MakeWebRequest(string requestUrl, CreateDownloadRequest 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<CreateDownloadResponse>(jsonResult);
        }