6

I have a client and a server.

On the client side I have:

HttpWebRequest request = 
    (HttpWebRequest)WebRequest.Create("http://localhost/fa/Default.aspx");
request.Method = "POST";                

byte[] data = Encoding.ASCII.GetBytes(GetSAMLRequestB64());

request.ContentType = "text/xml";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();

On the server side I have:

public void ProcessRequest(HttpContext httpContext) 
{
    HttpResponse response = httpContext.Response;             
    response.Clear();
    response.BufferOutput = true;
    response.StatusCode = 200; // HttpStatusCode.OK;
    response.Write("Hello");
    response.ContentType = "text/xml";
    response.End();
}

The client receives the response with the correct StatusCode. Although, if I do (int)response.ContentLength; on the client I get 0. I can't read the string "Hello" after I receive the response (client side).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user252816
  • 563
  • 4
  • 12
  • 21
  • 1
    I know this is an old thread, But may helps someone. Try http://stackoverflow.com/questions/4088625/net-simplest-way-to-send-post-with-data-and-read-response/19448979#19448979 – Murali Oct 18 '13 at 12:16

2 Answers2

3

Perhaps setting the content type before the actual write or flushing the stream would help.

m0sa
  • 10,712
  • 4
  • 44
  • 91
1

You didn't set ContentLength on the server. Maybe that would help?

John Saunders
  • 160,644
  • 26
  • 247
  • 397