Streaming byte array - WeOnlyDo Discussion board

Streaming byte array (wodHttpDLX)

by AtlantaGator, Thursday, August 24, 2017, 21:55 (2658 days ago) @ Jasmine

Jasmine,

Thanks for your assistance.

Here is my code:

string mytran = "Login Credentials and CC Data";
 
 
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
 
            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create("webaddress");
           
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            byte[] byteArray = Encoding.UTF8.GetBytes(mytran);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            Stream dataStream;
            try
            {
                // Get the request stream.
                dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
            }
 
            catch (Exception f)
            {
                MessageBox.Show(f.ToString());
            }
 
            // Get the response.
            WebResponse response = request.GetResponse();
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();


Complete thread: