简体   繁体   English

客户端应用在我的aspx页面上的Response.Write(..)之后的同一会话中发送请求。 我可以检索这些数据吗?

[英]Client app send request in same session after Response.Write( ..) on my aspx page. Can i retrieve this data?

There are two web application. 有两个Web应用程序。

WebApp1 send POST-request(1) to WebApp2. WebApp1将POST请求(1)发送到WebApp2。 Then WebApp2 send POST-response(2) to WebApp1. 然后,WebApp2将POST-response(2)发送到WebApp1。 I am developing WebApp2. 我正在开发WebApp2。 I create simple aspx-page. 我创建简单的aspx-page。 OnLoad event give me ability to process (1) & (2) and provide app logic. OnLoad事件使我能够处理(1)和(2)并提供应用程序逻辑。 To make response(2) I am using Response.Write(...). 为了使response(2)我正在使用Response.Write(...)。 But! 但! after response(2) WebApp1 send one more request to my app, to confirm, that my response recieved succesfully. 在response(2)之后,WebApp1向我的应用程序发送了另一个请求,以确认我的响应已成功收到。 That is the problem. 那就是问题所在。 I don't know how to catch (3). 我不知道该怎么抓(3)。 Response.Write(...) writes to response stream, but doesn't return any data from WebApp1. Response.Write(...)写入响应流,但不从WebApp1返回任何数据。

    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.HttpMethod == "POST")
        {
            logger.Trace(" -- POST REQUEST ...");
            string requestBody;
            using (StreamReader writer = new StreamReader(Request.InputStream))
            {
                requestBody = writer.ReadToEnd();
                logger.Trace("Request body:\n{0}", XmlHelper.FormatStringToXml(requestBody));
            }
            string responseBody = ProcessRequest(requestBody);

            logger.Trace("Response body:\n{0}", XmlHelper.FormatStringToXml(responseBody));
            if (!string.IsNullOrEmpty(responseBody))
            {
                SendPostXmlResponse(responseBody);
            }
            else
            {
                logger.Error("Cant send empty response. No response was sended.");
            }
        }
        else
        {
            logger.Error(" -- GET REQUEST is not supported. No actions were made.");
        }
    }


    private void SendPostXmlResponse(string response)
    {          
        Response.ContentType = "text/xml";
        Response.Clear();
        Response.BufferOutput = true;
        Response.Charset = "utf-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        using (MemoryStream stream = new MemoryStream (SmsService.StringToUTF8ByteArray(response)))
        {
            stream.WriteTo(Response.OutputStream);
        }
    }

Method SendPostXmlResponse(string response) must return data, recieved from client, after response is sended. 发送响应后,方法SendPostXmlResponse(string response)必须返回从客户端收到的数据。

The way you try to do it can not work because from the moment you start sending data, you can not stop sending and start reading again. 您尝试执行此操作的方法无效,因为从开始发送数据的那一刻起,您就无法停止发送并重新开始读取。

Its better to send a link to the other side with some code, and the other side replay to with a new call to this link as confirmation that get the data. 最好使用一些代码将链接发送到另一端,然后通过对该链接的新调用将另一端重播到另一端,以作为获取数据的确认。

At the bottom, if after you send all your data this parametre is Response.IsClientConnected is true, then the data are there and the communication is not lost. 在底部,如果在发送所有数据后此参数为Response.IsClientConnected为true,则数据在那里并且通信不会丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM