Authentication with HTTP libarary problem

agraham

Expert
Licensed User
Longtime User
What error do you get?
Are you using WebRequest.New3(...) ?
Hi Erel - Happy Xmas or whatever! I get a 401 exception thrown. No, I'm not using New3 - the Help only shows a New1 and a New2. I had assumed that I would need access to the Request headers to insert an Authorization line but they are read-only!

I have now tried New3 and get "Response.Value = Request.GetResponse" Error description: "The server committed a protocol violation. Section=ResponseHeader. Detail=CR must be followed by LF. Continue?"

The server in this case is the internal side of my router - I am practicing for a remote house monitoring system for a friend of mine. Looks like it won't work with the router - I shall have to wait for him to come up with the real server which will also have this sort of authentication.
 

agraham

Expert
Licensed User
Longtime User
I've seen this error before on one site.
I don't know how to explain it. Other sites (with authentication) work flawlessly.
Merry Christmas and a happy new year!
I googled for the error and I've fixed it now I know about New3. Needs this adding to the dbasic.exe.config (while debugging) and the exe.config of the final app. Can I suggest you do this on the next release!

B4X:
<system.net>
  <settings>
    <httpWebRequest useUnsafeHeaderParsing="true" />
  </settings>
</system.net
.NET is very (too) strict on parsing headers by default - this relaxes it.
 

agraham

Expert
Licensed User
Longtime User
Erel - idiot level questions I'm afraid!

I presume I need to "New3" the WebRequest object on every call to an authenticated server rather then "New1"s after the first. Does "KeepAlive" have any significance here?

I presume I also need to perform a "New1" and "Close" pair on the WebResponse for every call as well.

Thanks for the help so far.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…