Is there a library available for PureBasic which enables you to use SSL in a project?
For closer information, look at this, under the heading TWN Authentication. That's what I'm trying to do.
SSL for PureBasic?
Silly me!
Thanks for that headsup Pantcho! Anyways, it so happens that I don't want to POST, I want to send a GET request for a file named "pprdr.asp". There doesn't seem to be any explanation for HTTPS GET in the forum, so I'm wondering if anyone here knows how to do it?
Here's source from the forum that I've modified slightly to try to make it work (without luck):
This doesn't work.. what I end up with is a blank text file. What I need to do is this:
Send a blank HTTPS GET request for the asp file with no headers or anything like that. It should look like this:
GET /rdr/pprdr.asp HTTP/1.0\r\n
\r\n
Edit:
If done right, the server's response should look something like this:
Here's source from the forum that I've modified slightly to try to make it work (without luck):
Code: Select all
; English forum: http://purebasic.myforums.net/viewtopic.php?t=8302&highlight=
; Author: Karbon
; Date: 12. November 2003
; Note by Andre: I've changed #INTERNET_DEFAULT_HTTP_PORT = 443 to
; #INTERNET_DEFAULT_HTTPS_PORT = 443 (be aware of the additional 'S' at '_HTTPS_')
; because the #INTERNET_DEFAULT_HTTP_PORT constant is already declared in a .res
; file with another value
; This one does SSL, all you need to do for standard HTTP is change the
; INTERNET_FLAG_SECURE To 0 and the port to 80.
;
; All stuff for the WinInet lib.
;
#INTERNET_OPEN_TYPE_DIRECT = 1
#HTTP_ADDREQ_FLAG_ADD = $20000000
#HTTP_ADDREQ_FLAG_REPLACE = $80000000
#INTERNET_FLAG_SECURE = $800000
;
; Type of connection (could be FTP Gopher etc). HTTPS is done as HTTP too.
;
#INTERNET_SERVICE_HTTP = 3
;
; HTTP port is 80, HTTPS (SSL) port is 443.
;
#INTERNET_DEFAULT_HTTPS_PORT = 443
Procedure.s do_post()
;
; Do NOT include http:// or any other protocol indicator here
;
host.s = "nexus.passport.com"
;
; Everything after the hostname of the server
;
get_url.s = "/rdr/pprdr.asp"
;
; 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_("BlitzMessenger",#INTERNET_OPEN_TYPE_DIRECT,"","",0)
connect_handle = InternetConnect_(open_handle,host,#INTERNET_DEFAULT_HTTPS_PORT,"","",#INTERNET_SERVICE_HTTP,0,0)
request_handle = HttpOpenRequest_(connect_handle,"GET",get_url,"HTTP/1.0","",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)
post_data.s = ""
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
ProcedureReturn(result)
EndProcedure
test.s = do_post.s()
CreateFile(0, "test.txt")
WriteString(test.s)
Send a blank HTTPS GET request for the asp file with no headers or anything like that. It should look like this:
GET /rdr/pprdr.asp HTTP/1.0\r\n
\r\n
Edit:
If done right, the server's response should look something like this:
Code: Select all
<<< HTTP/1.1 200 OK\r\n
<<< Server: Microsoft-IIS/5.0\r\n
<<< Date: Mon, 02 Jun 2003 11:57:47 GMT\r\n
<<< Connection: close\r\n
<<< PassportURLs: DARealm=Passport.Net,DALogin=login.passport.com/login2.srf,DAReg=http://register.passport.net/uixpwiz.srf,Properties=https://register.passport.net/editprof.srf,Privacy=http://www.passport.com/consumer/privacypolicy.asp,GeneralRedir=http://nexusrdr.passport.com/redir.asp,Help=http://memberservices.passport.net/memberservice.srf,ConfigVersion=11\r\n
<<< Content-Length: 0\r\n
<<< Content-Type: text/html\r\n
<<< Cache-control: private\r\n
<<< \r\n
Update:
I checked out Google + MSDN and ended up with this:
Still isn't working...
Does anyone know why?
I checked out Google + MSDN and ended up with this:
Code: Select all
; All stuff for the WinInet lib.
;
#INTERNET_OPEN_TYPE_DIRECT = 1
#HTTP_ADDREQ_FLAG_ADD = $20000000
#HTTP_ADDREQ_FLAG_REPLACE = $80000000
#INTERNET_FLAG_SECURE = $800000
;
; Type of connection (could be FTP Gopher etc). HTTPS is done as HTTP too.
;
#INTERNET_SERVICE_HTTP = 3
;
; HTTP port is 80, HTTPS (SSL) port is 443.
;
#INTERNET_DEFAULT_HTTPS_PORT = 443
open_handle = InternetOpen_("BlitzMessenger",#INTERNET_OPEN_TYPE_DIRECT,"","",0)
hConnect = InternetConnect_(open_handle, "nexus.passport.com", #INTERNET_DEFAULT_HTTPS_PORT, "", "", #INTERNET_SERVICE_HTTP, 0, 0)
hReq = HttpOpenRequest_(hConnect, "GET", "/rdr/pprdr.asp", "", "", 0, #INTERNET_FLAG_SECURE, 0)
;
; Read until we can't read anymore..
; The string "result" will hold what ever the server pushed at us.
;
result$ = ""
buffer.s = Space(1024)
bytes_read.l
total_read.l = 0
Repeat
InternetReadFile_(hReq,@buffer,1024,@bytes_read)
result$ + Left(buffer,bytes_read)
buffer = Space(1024)
Until bytes_read=0
CreateFile(0, "test.txt")
WriteString(result$)
Does anyone know why?
If you send a get in the URL of an SSL connection for example https://www.mysite.com/index.php?id=3 (not a real url!)
I would expect the reply to be in SSL, which would mean you would have to decrypt it, or initialize the connection with open ssl dll's.
But as I've never done this, it's just a guess.
I would expect the reply to be in SSL, which would mean you would have to decrypt it, or initialize the connection with open ssl dll's.
But as I've never done this, it's just a guess.
Derek Gavey
- PB Newbie -
- PB Newbie -
Sorry about my last post... I see you are using winint.dll. I spent a few minutes looking at your problem and I think I have a soultion.
Here is the code...
The HttpSendRequest_ still has to be called even if your not sending modified headers.
One other problem though... I used the URL you had in your code, but it returns nothing. My example just pulls from google.com. I even tried your URL in a browser and still got a blank response.
Good luck with your code.
Here is the code...
Code: Select all
; ; All stuff for the WinInet lib.
;
#INTERNET_OPEN_TYPE_DIRECT = 1
#HTTP_ADDREQ_FLAG_ADD = $20000000
#HTTP_ADDREQ_FLAG_REPLACE = $80000000
#INTERNET_FLAG_SECURE = $800000
;
; Type of connection (could be FTP Gopher etc). HTTPS is done as HTTP too.
;
#INTERNET_SERVICE_HTTP = 3
;
; HTTP port is 80, HTTPS (SSL) port is 443.
;
#INTERNET_DEFAULT_HTTPS_PORT = 443
open_handle = InternetOpen_("BlitzMessenger",#INTERNET_OPEN_TYPE_DIRECT,"","",0)
hConnect = InternetConnect_(open_handle, "www.google.com", #INTERNET_DEFAULT_HTTPS_PORT, "", "", #INTERNET_SERVICE_HTTP, 0, 0)
hReq = HttpOpenRequest_(hConnect, "GET", "firefox?client=firefox-a&rls=org.mozilla:en-US:official", "", "", 0, #INTERNET_FLAG_SECURE, 0)
;Missing the HttpSendRequest_ this should fix it.
send_handle = HttpSendRequest_(hReq,"",0,0,"")
;
; Read until we can't read anymore..
; The string "result" will hold what ever the server pushed at us.
;
result$ = ""
buffer.s = Space(1024)
bytes_read.l
total_read.l = 0
Repeat
InternetReadFile_(hReq,@buffer,1024,@bytes_read)
Debug buffer
result$ + Left(buffer,bytes_read)
buffer = Space(1024)
Until bytes_read=0
CreateFile(0, "test.txt")
WriteString(result$)
One other problem though... I used the URL you had in your code, but it returns nothing. My example just pulls from google.com. I even tried your URL in a browser and still got a blank response.
Good luck with your code.
Derek Gavey
- PB Newbie -
- PB Newbie -