I have an aspx page that I'm trying to make an httprequest and then setup a TCP socket(I think this is what I'm doing lol)... I'm needing to send a byte array through this. I have this code so far, any advice/tips? Huge errors you see? I removed some items for my privacy. Basically I'm trying to send a simple byte array. Any help is greatly appreciated as I'm new to TCP and HttpRequests and WebRequests. I have a Webrequest currently, and I'm not sure if that's what's causing this not to work.

            byte[] buffer = { 254, 110, 1 };
            WebRequest request = WebRequest.Create("httpaddress.aspx");

            request.Method = "POST";

            request.ContentType = "application/x-www-form-urlencoded";

            request.ContentLength = buffer.Length;

            Stream PostData = request.GetRequestStream();

            TcpClient ourMagicClient = new TcpClient();
            ourMagicClient.Connect("DeviceIP", 2101);

            NetworkStream ourStream = ourMagicClient.GetStream();
            byte[] data = { 254, 109, 1 };
            ourStream.Write(data, 0, data.Length);

            PostData.Write(buffer, 0, buffer.Length);

            HttpWebResponse WebResp = (HttpWebResponse)request.GetResponse();
            Stream Answer = WebResp.GetResponseStream();
            StreamReader _Answer = new StreamReader(Answer);

It seems like I can connect to the device, but it doesn't respond through the page or to my byte array.

I'm not sure...I can use wifi to connect to the device just fine though. but that's not what i want to do.

Edited 2 Years Ago by kiail

This article has been dead for over six months. Start a new discussion instead.