HTTPRequest() continue using the connection

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

HTTPRequest() continue using the connection

Post 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.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: HTTPRequest() continue using the connection

Post 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.
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPRequest() continue using the connection

Post by infratec »

:wink:

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.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: HTTPRequest() continue using the connection

Post by Mijikai »

+1
Post Reply