SimpleBrowserDotNet/SimpleBrowser

Protocol Violation prevents update to CurrentHtml

Closed this issue · 5 comments

I'm using SimpleBrowser to automate interactions with a 3rd party site. In a certain scenario, for whatever reason, the 3rd party site is returning an HTTP status code of 0. When this happens, it appears that the Browser has a "The server committed a protocol violation" WebException cached in LastWebException, but the browser's CurrentHtml does not get updated with the body that is returned in that response. I have a workaround, but my ideal solution was to evaluate that content, even though the server returned an odd status code. I'm not suggesting that the exception should not occur, just suggesting that perhaps it makes sense to load the response HTML anyway.

Thanks for the great work!

Teun commented

Yes, good point. HTTP allows error statuses to send explaining HTML, so our browser should expose that HTML. It may break existing applications, however. Not sure how bad that would be.

@bledbet What was your work-around?

This specific use case has to do with logging into the site, and the HTML content that was in the response has some text in it that I can use to tell the difference between an expired password and a bad password - so that's why I say my ideal solution is to have access to that HTML. Luckily, the URL that the browser lands on (there is a series of forwards in the login process) includes a URL parameter that I can use to identify the fact that there was an authentication failure, though it doesn't help me tell the difference between expired password and bad password. So my workaround is that my browser proxy class subscribes to your browser class's HttpRequestLog events, and exposes a LastRequestedUrl property, which my service can use to at least tell the difference between an authentication failure and some other transient error.

I know this issue is ancient, but I decided to look into it today. There's two things going on here.

  1. In my testing where I'm returning a 0 HTTP Status Code from a WebAPI method with a string object content, I'm not seeing the application throwing an exception that appears in the Browser.LastWebException property. Perhaps there is something in addition to the 0 HTTP Status Code that is causing the exception to be thrown? I'm returning a 0 and not seeing the exception. There has to be something more that causes the exception.

  2. Putting the missing LastWebException aside, it doesn't look like this is possible in SimpleBrowser. Looking at the .NET System.Net.HttpWebResponse object (that SimpleBrowser wraps) received from an issued web request, the text or HTML response that is returned from the server is not in the .NET response object. It would appear that if .NET doesn't recognize the HTTP Status Code, it strips the content. It sucks, but if .NET doesn't give it to us, we can't get it.

I'm going to close this for now. There hasn't been any response from the original reporter of the issue. Even if there were, I don't think there's anything that can be done anyway (at least not without more information).