Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

MailChimp C# Api calls

private string CallMailChimpApi(string method, string requestJson, string key)
    {
        var endpoint = String.Format("https://{0}.api.mailchimp.com/3.0/{1}", "<datacenter>", method);
        byte[] dataStream = Encoding.UTF8.GetBytes(requestJson);
        var responsetext = string.Empty;
        WebRequest request = HttpWebRequest.Create(endpoint);
        WebResponse response = null;
        try
        {
            request.ContentType = "application/json";
            SetBasicAuthHeader(request, "anystring", key);  // BASIC AUTH
            request.Method = "POST";
            request.ContentLength = dataStream.Length;
            Stream newstream = request.GetRequestStream();

            newstream.Write(dataStream, 0, dataStream.Length);
            newstream.Close();

            response = request.GetResponse();

            // get the result
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                JsonSerializer json = new JsonSerializer();
                JObject content = JObject.Parse(reader.ReadToEnd());

                responsetext = reader.ReadToEnd();
            }

            response.Close();
        }

        catch(WebException ex)
        {
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                responsetext = sr.ReadToEnd();
            }
        }
        return responsetext;
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity add text to text field without deleting the old one 
Csharp :: unity ik not working 
Csharp :: Load Level Action for unity 
Csharp :: 0.8 dikali 0.8 
Csharp :: make winform open first 
Csharp :: c# udpclient receive buffer size 
Csharp :: c# todatatable nullable 
Csharp :: .net directorysearcher get manager accountname 
Csharp :: git change remote origin 
Html :: html 5 default code 
Html :: html tab icon 
Html :: how to import font awesome in html 
Html :: accept only image input file 
Html :: no follow no index 
Html :: html disable drag image 
Html :: editable div 
Html :: bootstrap col-md-5 center 
Html :: mirror html video element 
Html :: lorem ipsum 
Html :: bootstrap footer bottom of page 
Html :: dropdown first option not selectable 
Html :: favicon for html page 
Html :: mobile prevent zoom 
Html :: how to embed videos in html 
Html :: html click to call 
Html :: mute video html 
Html :: escape double quotes in html 
Html :: html link para descargar archivo de audio 
Html :: checked bootstrap 5 
Html :: basecamp 3 api tag mention 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =