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

在客户端我有:

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”我收到的响应(客户端)之后。

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top