Skip to content

Unable to read entire response! #3

@suryaprayaga

Description

@suryaprayaga

Hi,
I'm facing a critical issue in my windows phone development.
I'm using Bouncy Castle library to handle https requests POST and GET.

Here is a glimpse of the code
using (var tcpConnection = new SecureTcpConnection())
{
// Keep connection open when performing multiple requests.
tcpConnection.Connect(hostName, port);

                // Write the request.
                var streamWriter = new StreamWriter(tcpConnection.Stream);
                streamWriter.WriteLine("I'm sending the post message with header and parameters here");
                streamWriter.Flush();

                // Read the response.
                var streamReader = new StreamReader(tcpConnection.Stream);

                var fullMessage = new StringBuilder();

                string message;
                while ((message = streamReader.ReadLine()) != null)
                {                       
                    int s = fullMessage.Length;
                    if (string.IsNullOrWhiteSpace(message))
                    {     

// after reaading the new line the code tries to read the content and waits for ever.
// HTTP header is read.
// The content-length header should be used now to determine how many bytes should be read now.
// break;
}
}

                    fullMessage.AppendLine(message);

                string result = fullMessage.ToString();
            }

The connection is established perfectly. The weird problem here is the SSL connection is established perfectly and i'm able to read all the headers which also includes content length but after the headers it reads the new line and when it is trying to read content after the new line the application hangs forever when trying to ready.
public override int Read(byte[] buffer, int offset, int count)
{
// the socker.recieveasync(e) is always waiting and indicates the operation is not completed yet.
}
I'm not able to get the actual reason for this. I tried to check in the back-end if there is some issue in the request i sent but it works perfectly there. But when i try to connect it via my phone and check the app hangs and unit test also hangs as well at the same point.
This is very crucial issue for me as i'm planning a release soon for my app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions