;/ Author : Karbon
#INTERNET_OPEN_TYPE_DIRECT = 1
#HTTP_ADDREQ_FLAG_ADD = $20000000
#HTTP_ADDREQ_FLAG_REPLACE = $80000000
#INTERNET_FLAG_SECURE = 0 ;/ $800000 si HTTPS
#INTERNET_SERVICE_HTTP = 3 ; Type of connection (could be FTP Gopher etc). HTTPS is done as HTTP too.
#INTERNET_DEFAULT_HTTP_PORT = 80 ;/ 443 si HTTPS
#HTTP_QUERY_COOKIE = 44 ; ;For httpqueryinfo.
Procedure.s do_post(username.s, Password.s)
;
; Do NOT include http:// or any other protocol indicator here
;
host.s = "purebasic.fr"
;
; Everything after the hostname of the server
;
get_url.s = "/english/login.php"
;
; Holds the result from the CGI/page
;
result.s = ""
;
; All from the wininet DLL
;
; Be sure your Internet Explorer is up to date!
;
open_handle = InternetOpen_("User Agent Info Goes Here", #INTERNET_OPEN_TYPE_DIRECT, "", "", 0)
connect_handle = InternetConnect_(open_handle, host, #INTERNET_DEFAULT_HTTP_PORT, "", "", #INTERNET_SERVICE_HTTP, 0, 0)
request_handle = HttpOpenRequest_(connect_handle, "POST", get_url, "", "", 0, #INTERNET_FLAG_SECURE, 0)
headers.s = "Content-Type: application/x-www-form-urlencoded" + Chr(13)+ Chr(10)
HttpAddRequestHeaders_(request_handle, headers, Len(headers), #HTTP_ADDREQ_FLAG_REPLACE | #HTTP_ADDREQ_FLAG_ADD)
; change this when using a login form other than a phpbb one
post_data.s = "username = " + username +"&password = " + Password +"&login = Log%20in" ; not sure why the submit button text is needed.... but it seemed to make it work for me :lol:
post_data_len = Len(post_data)
send_handle = HttpSendRequest_(request_handle, "", 0, post_data, post_data_len)
Buffer.s = Space(1024)
bytes_read.l
total_read.l
total_read = 0
;
; Read until we can't read anymore..
; The string "result" will hold what ever the server pushed at us.
;
Repeat
InternetReadFile_(request_handle, @Buffer, 1024, @bytes_read)
result + Left(Buffer, bytes_read)
Buffer = Space(1024)
Until bytes_read = 0
;- uncomment the following when you want to get the cookie data - not sure if it works or not.....
; buffer.s = Space(#MAX_PATH)
; headernum = 0
; length = Len(buffer)
; HttpQueryInfo_(request_handle, #HTTP_QUERY_COOKIE, @buffer, @length, @headernum)
; Debug buffer
ProcedureReturn result
EndProcedure
do_post("login", "password")
OpenWindow(0, 0, 0, 1024, 768, "WebGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
WebGadget(0, 10, 10, 1004, 748, "http://www.purebasic.fr/english/index.php")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow