Beispiel #1
0
 public static string SerializePostValue(PostValues obj)
 {
     JavaScriptSerializer ser = new JavaScriptSerializer();
     StringBuilder serialized = new StringBuilder();
     ser.Serialize(obj, serialized);
     return serialized.ToString();
 }
Beispiel #2
0
        public void PutDocument(PostValues value, string indexName)
        {
            string username = System.Configuration.ConfigurationManager.AppSettings["Username"];
            string password = System.Configuration.ConfigurationManager.AppSettings["Password"];
            string url = System.Configuration.ConfigurationManager.AppSettings["URL"];

            string postData = Serilizer.SerializePostValue(value);
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(postData);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url + "/v1/indexes/" + indexName + "/docs");

            byte[] credentialBuffer = new UTF8Encoding().GetBytes(username + ":" + password);
            request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer);

            request.Method = "PUT";
            request.ContentType = "application/json";
            request.ContentLength = byte1.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byte1, 0, byte1.Length);
            dataStream.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string returnString = response.StatusCode.ToString();
        }