2

I have a C# server that will accept connections from a game/client and return information from a database to the game/client.

The client posts an xml file. I would like to send a 200 OK Response back to the client.

I have tried numerous things. Can anyone suggest something. I also need the response to HTTP 1.0.

Thanks.

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
  • 5
    You tried numerous things. Can you share those with us? That might clarify and prevent some people reinventing your wheel, which is not helpfull to you. – rene Feb 16 '11 at 23:05
  • possible duplicate of [Setting response status code manually](http://stackoverflow.com/questions/678433/setting-response-status-code-manually) – NotMe Feb 16 '11 at 23:10
  • I tried using the Http Response class and the HttpWebResponse class as well. However, the outputstream seems to a text writer. I just want it to stream back across the network. I want to do something similar to Java's BasicHttpResponse. Thanks. – Jonathan Harris Feb 16 '11 at 23:21

3 Answers3

0

If you're looking to write an application that serves web requests with responses and want it to be (relatively) lightweight, at least in regards to IIS, try looking into the Kayak Project. Seems pretty close to what you're aiming to do.

This thread in the mailing list seems especially relevant.

Kilanash
  • 4,479
  • 1
  • 14
  • 11
0

Your question is so confusing... "send back" without request in the title... but a request is done when you explain later the full problem...

Anyway, I don't know if this is what you want to do, but can send your own headers using the Status and StatusCode properties of the HttpResponse class.

davidcm
  • 165
  • 3
  • 11
  • Sorry for the confusion but i wanted to do something similar to Java's BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK"); iOut.write(response.toString().concat(CRLF + CRLF).getBytes()); – Jonathan Harris Feb 16 '11 at 23:16
0

So I didn't really understand the http response. I forgot to send back the two CRLF at the end of the response. Thanks alot.

--definitions:   CRLF = "\r\n"; s = NetworkStream().


StringBuilder str = new StringBuilder();
str.Append("HTTP/1.0 200 OK\r\n");
str.Append("Date: Tue, 17 Aug 2011 11:40:00 EST\r\n");
str.Append("Server: Apache\r\n");
str.Append("Content-Type: text/xml\r\n");
str.Append("Content Length: 128\r\n");

byte [] r = Encoding.ASCII.GetBytes(str.ToString() + CRLF+ CRLF);
s.Write(r, 0, r.Length);
Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46