I have created something like this: https://www.codeproject.com/Tips/485182/Create-a-local-server-in-Csharp
But the tutorial only shows how to send a string. But when I try to modify the code by adding an img src
, it won't show up. This is what I have done so far:
private void sendData(int total, DataGridView dgv, Image v)
{
Thread t = new Thread(() => ResponseThread(total, dgv,v));
t.Start();
}
private void ResponseThread(int t, DataGridView dgv, Image u)
{
String table="";
HttpListenerContext context = _httpListener.GetContext();
for (int i = 0; i < t; i++)
table += "<tr><td>" + dgv.Rows[i].Cells[0].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[1].Value.ToString() + "</td><td>" +
dgv.Rows[i].Cells[2].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[3].Value.ToString() + "</td><td>" + dgv.Rows[i].Cells[4].Value.ToString() +
"</td><td>" + dgv.Rows[i].Cells[5].Value.ToString() + "</td></tr>";
byte[] _responseArray = Encoding.UTF8.GetBytes(
"<html>" +
"<head>" +
"<title>Hello</title>" +
"</head>" +
"<body>" +
"<h1>Total: " + t +
"<table style=\"width:100%\"> <tr><b><th>No</th><th>Centroid X</th><th>Centroid Y</th><th>Orientation</th><th>Area</th><th>Area (mm)</th></b></tr>"+
table+"</table>"+
"<img src="+u+"></img>"+
"<p><i>Last Update: " + DateTime.Now.ToShortDateString() + " "+DateTime.Now.ToLongTimeString()+
"</i></p>" +
"</h1></body></html>");
context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length);
context.Response.KeepAlive = true;
context.Response.Close();
}