0

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);
            PostData.Close();

            HttpWebResponse WebResp = (HttpWebResponse)request.GetResponse();
            Stream Answer = WebResp.GetResponseStream();
            StreamReader _Answer = new StreamReader(Answer);
            Console.WriteLine(_Answer.ReadToEnd());
            Console.WriteLine(WebResp.StatusCode);
            Console.WriteLine(WebResp.Server);
            Console.WriteLine(_Answer.ReadToEnd());
            Console.ReadKey();
1
Contributor
2
Replies
8
Views
2 Years
Discussion Span
Last Post by kiail
0

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

0

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 by kiail

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.