Page 1 of 1
HTTPRequest() continue using the connection
Posted: Fri Aug 12, 2022 7:36 am
by infratec
I just need to use my libcurl.pbi again, because at the moment it is impossible (is it Fred?) to do more then one HTTPRequest with the same connection.
I needed to login to a webpage and afterwards download something.
With HTTPRequest() it was not possible, because for each new connection a new token is generated by the webpage.
So I had to use libcurl directly and using the same curl handle for all requests.
Question to Fred:
If I don't use FinishHTTP(), is the same curl handle used for the next request?
Is then the slist for the headers reset?
There should be a possibility to reuse the same connection, else something like I described is not possible with PB directly.
Re: HTTPRequest() continue using the connection
Posted: Fri Aug 12, 2022 10:41 pm
by helpy
If HTTP pages need a login and token handling for authentication, you have to do this in your application:
- After login you have to parse the response to save the cookies and also the token (which is probably passed inside a cookie).
- With the next request you have to pass the cookies (containing the authentication token) back to the server.
- Some servers need to pass the token with a special header field. This depends on the server application.
- As far as I know libcurl can do this session/cookie handling automatically. Using PureBasics HTTP methods you have to do this handling yourself.
- Additionally the server application could also use some CSRF prevention techniques. If this is the case ... you also have to handle this according to the rules of the server application.
I already did this with an intranet application, which is running in our company network.
Re: HTTPRequest() continue using the connection
Posted: Sat Aug 13, 2022 9:07 am
by infratec
I know how to do it. Trust me.
As written: it was not possible with PB, since the server changed the token cause of the complete new TCP connection.
And also as written: I was able to do it with my libcurl low level procedures.
Re: HTTPRequest() continue using the connection
Posted: Sat Aug 13, 2022 10:18 am
by Mijikai
+1
Re: HTTPRequest() continue using the connection
Posted: Wed Nov 20, 2024 7:05 pm
by Wolfram
Hello infratec,
have you found a solution for PB in the meantime?
Re: HTTPRequest() continue using the connection
Posted: Thu Nov 21, 2024 10:10 am
by infratec
No,
i still need my libcurl stuff. But this works also on macOS.
Re: HTTPRequest() continue using the connection
Posted: Mon Nov 25, 2024 6:15 am
by Psych
infratec wrote: Sat Aug 13, 2022 9:07 am
I know how to do it. Trust me.
As written: it was not possible with PB, since the server changed the token cause of the complete new TCP connection.
And also as written: I was able to do it with my libcurl low level procedures.
This makes no sense to me, all HTTP requests are stateless, meaning each request is a new connection (unless you use some sort of KEEP-ALIVE header, which many servers just ignore). Sending your session-id cookie value back to the server keeps the session alive.
@helpy gave the correct answer.
Simply read all the headers into a map and send them back with the next request.