Page 1 of 1

HTTPS in PB?

Posted: Tue Oct 11, 2005 3:09 pm
by Kaiser
Yeah, it is possible to get/send some data using the HTTPS protocol in PB? I've heard about WININET.DLL and that one source code in PureArea but doesn't seems to help me... or at least the code's way too hard for me to understand... but don't know anything about WININET.DLL nor how to use it in PB (A wrapper would do nicely) so... any way I can get/send data using HTTPS in PB?

Posted: Tue Oct 11, 2005 5:33 pm
by Killswitch
If you're talking about a webserver there's a few examples, the Atomic Webserver an KNet (a program I've written) are just two and the source is included with PB or on the fourms.

Posted: Tue Oct 11, 2005 5:37 pm
by Kaiser
By webserver you mean hosting or accessing it?

Posted: Tue Oct 11, 2005 5:39 pm
by KameHameHaaa
This is an include file that I built "stealing" form this forum and adding other needed parts reading MSDN.

Code: Select all

; All stuff for the WinInet lib.
#INTERNET_OPEN_TYPE_DIRECT              = 1
#INTERNET_OPEN_TYPE_PRECONFIG           = 0
#HTTP_ADDREQ_FLAG_ADD                   = $20000000
#HTTP_ADDREQ_FLAG_REPLACE               = $80000000
#INTERNET_FLAG_SECURE                   = $800000
#INTERNET_FLAG_RELOAD                   = $80000000
#INTERNET_FLAG_PRAGMA_NOCACHE           = $100
#INTERNET_FLAG_KEEP_CONNECTION          = $400000
#INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP  = $8000
#INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS = $4000
#INTERNET_FLAG_IGNORE_CERT_CN_INVALID   = $1000
#INTERNET_FLAG_IGNORE_CERT_DATE_INVALID = $2000
#INTERNET_FLAG_EXISTING_CONNECT         = $20000000
  
; Type of connection (could be FTP Gopher etc). HTTPS is done as HTTP too.
#INTERNET_SERVICE_HTTP = 3

; custom
#INTERNET_HTTP_PORT=80
#INTERNET_HTTPS_PORT=443

;#INTERNET_FLAG_SECURE

Procedure.s do_post (host.s, url.s, login.s , password.s, port, secureflag)
  
  result.s = ""
 
  ; All from the wininet DLL
  open_handle = InternetOpen_("GR monitor",#INTERNET_OPEN_TYPE_PRECONFIG,"","",0); proxy;INTERNET_OPEN_TYPE_PRECONFIG;INTERNET_OPEN_TYPE_DIRECT
  connect_handle = InternetConnect_(open_handle,host,port,"","",#INTERNET_SERVICE_HTTP,0,0)
  request_handle = HttpOpenRequest_(connect_handle,"POST",url,"","",0,secureflag | #INTERNET_FLAG_IGNORE_CERT_CN_INVALID | #INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | #INTERNET_FLAG_RELOAD | #INTERNET_FLAG_PRAGMA_NOCACHE | #INTERNET_FLAG_KEEP_CONNECTION | #INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS | #INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP,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)

  post_data.s = "login=" + login +"&passwd=" + password + "&dataora=" + dataora
  post_data_len = Len(post_data)
  send_handle = HttpSendRequest_(request_handle,"",0,post_data,post_data_len)
 
  buffer.s = Space(1024)
  bytes_read.l = 0
  total_read.l = 0
 
  ; Read until we can't read anymore..
  ct=0
  Repeat
    z=InternetReadFile_(request_handle,@buffer,1024,@bytes_read)
    result + Left(buffer,bytes_read)
    buffer = Space(1024)
    ct+1
  Until bytes_read=0
  
  err.s=LastError()
  If err<>""
    result="<message>Error:" + Chr(13) + err + "</message>"
  EndIf

  ProcedureReturn result
EndProcedure 

Posted: Thu Oct 13, 2005 2:40 am
by Kaiser
Uh, that looks interesting... now how the hell does it work? I know that code snippet... and nice modification you made, but it didn't explained anything about the API commands there.... and the MSDN didn't helped me :?

Posted: Sun Oct 23, 2005 2:31 am
by Kaiser
Anyone? :S 'cause I'm making an MSN client and need to do the HTTPS authentication in it :/