HTTP Library Walkthrough

Zenerdiode

Active Member
Licensed User
I'm trying for the first time to use the HTTP library - but I'm struggling even with the example. We have some logging devices that present the most simplistic Web Page to the user; a blank page with a few links for the date/time of the log and the log is just a text file. So for example you click a 'Files' link, click '20100118' and finally right-click '1000.txt' to download the 10:00 file for today. The user has to first log in at the message box dialog.

New3 should be used with web pages that show a message box that asks for username and password.

I'm falling at the first hurdle because when I use:

B4X:
Request.New3("http://10.0.1.1/Files","user","user")
Request.Timeout=60000
Response.Value=Request.GetResponse

it fails with:
Response.Value=Request.GetResponse
Error description:
Response code: -1
ServerProtocolViolation
 

agraham

Expert
Licensed User
Longtime User
The .NET HTTP client protocol handler is very picky about correct header formatting. I had similar trouble with a PIC based remote controller, also using authentication, that returned a response with only a single CRLF terminating the header section instead of two as the protocol specifies. Even after the firm tried putting the additional CRLF in for me it still failed so there was something else wrong as well. Browsers worked fine with it as they seem to be programmed to accept all sorts of malformed responses but the .NET HttpClient seems to require strict adherence to the specification. This might (or might not!) be your problem.

I worked around it using a Client from the Network library and rolled my own authentication as in the example attached. Luckily I only needed a single GET to send commands and get the information I needed back as a simple web page.
 

Attachments

  • Authenticate.zip
    4.5 KB · Views: 280

mjcoon

Well-Known Member
Licensed User
It fails with:
Response.Value=Request.GetResponse
Error description:
Response code: -1
ServerProtocolViolation

Not sure if it will help with your particular problem, but when I was still at work and struggling with HTTP I made good use of Fiddler2. It's a freebie interceptor that allows you to write a filter script that modifies the HTTP and forwards it on.

Mike.
 
Top