6

我有一个客户端和一个服务器。

在客户端,我有:

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();

在服务器端,我有:

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();
}

客户端收到正确的响应StatusCode。虽然,如果我(int)response.ContentLength;在客户端上做,我得到 0。在收到响应(客户端)后,我无法读取字符串“Hello”。

4

2 回答 2

3

也许在实际写入或刷新流之前设置内容类型会有所帮助。

于 2010-02-11T19:12:00.660 回答
1

您没有在服务器上设置 ContentLength。也许这会有所帮助?

于 2010-02-11T19:12:09.457 回答