Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making http request from code behind

Tags:

c#

asp.net

I am trying to implement Message API

I am not sure how I will be calling this from code-behind and in their snippet it says:

https://platform.3cinteractive.com/api/send_message.php 

POST
username=aRDSe3vcaMzh06YrMcxcQw==&password=1BSvQc6lpNlnp4ufWgRLPHNJ7RMrL8CcaWCzL1Vtw+Y=&phone_number=+11234567890&trigger_id=1105&message=howdy
like image 493
Nick Kahn Avatar asked Sep 08 '26 02:09

Nick Kahn


2 Answers

Use the WebRequest class below or use a library like RestSharp for more control or your HTTP request:

// Create a request for the URL.        
WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Display the status.
Console.WriteLine (response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();
like image 200
rick schott Avatar answered Sep 10 '26 16:09

rick schott


You need to use a WebRequest and do an HTTP POST. See this article entitled How to: Send Data Using the WebRequest Class.

like image 20
John Sobolewski Avatar answered Sep 10 '26 15:09

John Sobolewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!