DarkDucke 2 Posted November 11, 2019 Hello, I am trying to get data from a page and am getting error "206", the only detail is a "Authorization: Bearer" header. I'm entering the header in event "BeforeHeaderSend" Headers.Add('Authorization:Bearer ' + mToken.Text); HttpCliSusp.Connection := 'Keep-Alive'; HttpCliSusp.ContentTypePost := 'application/json;charset=UTF-8'; HttpCliSusp.RequestVer := '1.0'; HttpCliSusp.RcvdStream := TMemoryStream.Create; HttpCliSusp.URL := 'https://www.url-to-get.com'; HttpCliSusp.Get; i get HttpCliSusp.StatusCode = 206 Using the Indy component "TIdHttp" I get the content normally without error! IdHttp.Request.CustomHeaders.Add('Authorization:Bearer ' + mToken.Text); xHtmlRetorno := IdHttp.Get('https://www.url-get.com'); xHtmlRetorno comes content without errors. Where am I going wrong using the ICS TSslHttpCli component? Thanks!!! Share this post Link to post
Angus Robertson 577 Posted November 11, 2019 One possible reason is HTTP 1.0 does not support Keep-Alive, it should be 1.1. You are also setting a POST content type but using GET. That component added httpAuthBearer 18 months ago so you are probably using an old version. You would be better using the newer TSslHttpRest component that is much easier to use than THttpCli and has a new demo OverbyteIcsHttpRestTst.dpr designed for OAuth2. REST and Json. Angus Share this post Link to post
DarkDucke 2 Posted November 11, 2019 4 hours ago, Angus Robertson said: One possible reason is HTTP 1.0 does not support Keep-Alive, it should be 1.1. You are also setting a POST content type but using GET. That component added httpAuthBearer 18 months ago so you are probably using an old version. You would be better using the newer TSslHttpRest component that is much easier to use than THttpCli and has a new demo OverbyteIcsHttpRestTst.dpr designed for OAuth2. REST and Json. Angus Hello, I updated the component to the latest version "8.62". I am using it as follows: HttpCliSusp.Connection := 'Keep-Alive'; HttpCliSusp.ContentTypePost := 'application/json;charset=UTF-8'; HttpCliSusp.AuthBearerToken := mToken.Text; HttpCliSusp.RequestVer := '1.1'; HttpCliSusp.RcvdStream := TMemoryStream.Create; HttpCliSusp.URL := 'url-to-get'; HttpCliSusp.Get; And Now I get the error: Invalid argument to date encode. I'm not using the event "BeforeHeaderSend" Share this post Link to post
Remy Lebeau 1436 Posted November 11, 2019 6 hours ago, DarkDucke said: Hello, I am trying to get data from a page and am getting error "206" The ONLY time a web server should ever send a 206 response code is if the request contained a "Range" header asking for a specific range of bytes in the response data. That doesn't make sense to do in this situation. So double check that you are not setting up your TSslHttpCli to send such a request header. 6 hours ago, DarkDucke said: Using the Indy component "TIdHttp" I get the content normally without error! TIdHTTP does not send a "Range" request header unless you explicitly ask it to, via the TIdHTTP.Request.Range(s) properties. Share this post Link to post
Remy Lebeau 1436 Posted November 11, 2019 5 hours ago, Angus Robertson said: One possible reason is HTTP 1.0 does not support Keep-Alive, it should be 1.1. Even though "keep-alive" wasn't standardized until HTTP 1.1, most HTTP 1.0 servers do recognize it. But either way, the "Connection" request header has nothing to do with this issue. 5 hours ago, Angus Robertson said: You are also setting a POST content type but using GET. Definitely something that should be fixed in the user's code, but again, not the root cause of the issue. The HTTP server will just ignore a "Content-Type" header in a GET request. Share this post Link to post
Angus Robertson 577 Posted November 12, 2019 11 hours ago, DarkDucke said: And Now I get the error: Invalid argument to date encode. Which must be the result of code you have not shown, you need to use the debugger. You should build the OverbyteIcsHttpRestTst.dpr sample and try your URL using the GUI first. Angus Share this post Link to post