2

I have seen many examples on this site showing the webrequest equivalent of curl, however, as I have absolutely no php experience at all, it still leaves me dumbfounded.

Can somebody please show me the webrequest equivalent of this curl command:

curl  -H "Content-Type:application/json" -X POST -d '{"name":"download_casestudy_a","casestudy":"A","type":"trackLink","href":"http://www.example.com","key":"your_key","session_id":"f33234de-cc75-4f28-9e9a-afb0014a5daf"}' https://in-automate.sendinblue.com/p

1 Answer 1

3

Sending a request with your given options and data migth look like this:

static void Main(string[] args)
        {
            var request = WebRequest.Create(new Uri("https://in-automate.sendinblue.com/p"));
            var json =
                "'{'name':'download_casestudy_a','casestudy':'A','type':'trackLink','href':'http://www.example.com','key':'your_key','session_id':'f33234de-cc75-4f28-9e9a-afb0014a5daf'}'";
            request.Headers.Add("Content-Type", "application/json");
            request.Method = "POST";
            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }


            var httpResponse = (HttpWebResponse)request.GetResponse();
            using (var streamReader = new StreamReader(stream: httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }

        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.