/// <summary> /// Creates the asset. /// </summary> /// <param name='asset'> /// Asset. /// </param> /// <exception cref='InvalidOperationException'> /// Is thrown when an operation cannot be performed. /// </exception> public void CreateAsset(CreateAsset asset ) { if(asset == null) throw new InvalidOperationException("Asset is required"); string url = BuildRequestURL(EXPORT_URI + CREATE_ASSET_URI); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Accept = "application/json"; request.ContentType = "application/json"; request.Credentials = GetCredential(url); request.Method = "POST"; byte[] byteData = UTF8Encoding.UTF8.GetBytes(asset.ToString()); // Set the content length in the request headers request.ContentLength = byteData.Length; // Write data using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } // Get response using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if(response.StatusCode != HttpStatusCode.OK) throw new Exception(response.StatusCode.ToString()); // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); // Console application output Console.WriteLine(reader.ReadToEnd()); } }