Beispiel #1
0
        public static ResponseBuilder Connect(RequestBuilder request)
        {
            ResponseBuilder response = new ResponseBuilder();

            try
            {
                Socket s = Connect(request.CurrentURL.Host, request.CurrentURL.Port);
                if (s == null)
                {
                    throw new Exception("Connection failed");
                }

                Byte[] bytesSent     = Encoding.UTF8.GetBytes(request.ToString());
                Byte[] bytesReceived = new Byte[request.ToString().Length];

                // Send request to the server.
                s.Send(bytesSent, bytesSent.Length, 0);
                int bytes = 0;
                do
                {
                    // Receive response to the server.
                    bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
                    response.Append(Encoding.UTF8.GetString(bytesReceived, 0, bytes));
                }while (bytes > 0);
            }
            catch (Exception ex)
            {
                response.Clear();
                response.AppendLine(ex.Message);
                response.AppendLine(ex.StackTrace);
            }
            return(response);
        }
        public void HandlePostRequest(string content_type = "text/html")
        {
            writeSuccess(content_type);
            writeOptions();
            writeClose();
            string requestBuilder = RequestBuilder.ToString();//.Trim(new char[] { '\n', '\r' });

            ResponseBuilder.AppendLine(requestBuilder);
            string responseString = ResponseBuilder.ToString();//.TrimEnd(new char[] { '\n', '\r' });

            binSend = responseString.ToBytes(CharEncoding.UTF8);
        }
        private void writeOptions()
        {
            if (HttpOptions.Count > 0)
            {
                foreach (DictionaryEntry option in HttpOptions)
                {
                    ResponseBuilder.AppendLine(string.Format("{0}: {1}", option.Key, option.Value));
                }
            }

            ResponseBuilder.AppendLine("Accept: application/json");
            ResponseBuilder.AppendLine("Access-Control-Allow-Headers: content-type");
            ResponseBuilder.AppendLine("Access-Control-Allow-Origin: " + HttpHeaders["Origin"].ToString());
        }
 private void writeClose(string state = "close")
 {
     ResponseBuilder.AppendLine("Connection: " + state);
     ResponseBuilder.AppendLine("");
 }
 private void writeDenied()
 {
     ResponseBuilder.AppendLine("HTTP/1.1 401.7 Access denied by authorization strategy on VSSP server");
 }
 private void writeFailure()
 {
     ResponseBuilder.AppendLine("HTTP/1.1 404 File not found");
 }
 private void writeSuccess(string content_type = "text/html")
 {
     ResponseBuilder.AppendLine("HTTP/1.1 200 OK");
     ResponseBuilder.AppendLine("Content-Type: " + content_type);
 }
Beispiel #8
0
 /// <summary>
 /// The writeDenied.
 /// </summary>
 private void writeDenied()
 {
     ResponseBuilder.AppendLine("HTTP/1.1 401.7 Access denied");
 }