public bool SendMessageByTcp(IMyNetWorkStream stream, string statusCode, string message) { if (statusCode == "") { return(false); } string response = $"HTTP/1.1 {statusCode} {ResolveHTTPStatuscode(statusCode)}\r\n"; foreach (var item in DicionaryHeaders) { response += $"{item.Key}: {item.Value}\r\n"; } response += "\r\n"; response += $"Content-Length: {message.Length}\r\n\r\n{message}"; byte[] msg = System.Text.Encoding.ASCII.GetBytes(response); try { stream.Write(msg, 0, msg.Length); } catch { return(false); } return(true); }
public bool SendDefaultMessage(IMyNetWorkStream stream, string statusCode, string message) { if (statusCode == "") { return(false); } string response = $"HTTP/1.1 {statusCode} {ResolveHTTPStatuscode(statusCode)}\r\nCache-Control: no-cache\r\nDate: {DateTime.Now}\r\nConnection: Closed\r\nContent-Type: application/json\r\nContent-Length: {message.Length}\r\n\r\n{message}"; byte[] msg = System.Text.Encoding.ASCII.GetBytes(response); try { stream.Write(msg, 0, msg.Length); } catch { return(false); } return(true); }