Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTPS Post

Status
Not open for further replies.

jackmason

Programmer
Jul 28, 2009
13
US
I am trying to turn an HTTP component into an HTTPS component to connect to Amazon. I am using D7. Here is what I have so far with an Indy 9 HTTP client component named HTTPS:

var Authorization, Response, Headers: string;
begin
Authorization := MimeEncodeString('myusername:mypassword');

HTTPS.Request.URL := '
Headers := 'Authorization: Basic ' + Authorization +
' Content-Type: text/xml ' + Cookie.Text; // Cookie is a predefined string

HTTPS.Post(URL.Text, Headers, Response);

D7 complains that there is no overloaded version of POST that can be called with those parameters even though D7 performs a code completion with the overloaded version above.

I do have libeay32.dll and ssleay32.dll in my development directory.

I also have a TIdSSLIOHandlerSocket named IdSSLIOHandlerSocket1 and the following lines do compile if I insert them:

HTTPS.IOHandler := IdSSLIOHandlerSocket1;
IdSSLIOHandlerSocket1(HTTPS.IOHandler).SSLOptions.Method := sslvSSLv3;

What I am trying to accomplish is send the Authorization, Content-Type, and Cookie as "Headers" in an HTTPS connection to the Amazon URL.

Thanks for any help you can provide.
 
I'm guessing you've seen my post recently about using HTTPS.

I recommend upgrading to Indy 10, as there have been many improvements, and it may solve your problem. I cannot confirm this though. And, unfortunately, it may break some of your existing code. It shouldn't be too difficult to downgrade again though if Indy 10 proves unworkable for you.

 
I can upgrade to Indy10, but that still doesn't give me an HTTPS component so I need to turn an HTTP component into an HTTPS one. I believe I am almost there by adding the code:

HTTPS.IOHandler := IdSSLIOHandlerSocket1;
IdSSLIOHandlerSocket1(HTTPS.IOHandler).SSLOptions.Method := sslvSSLv3;

but, I haven't figured out why D7 will autocomplete the HTTPS.Post to have 3 arguments but will not compile it, or if the above code is all it takes to make the HTTP component into an HTTPS one.
 
I'm using D6 with Indy 10, and I don't have a version of Post that takes 3 strings.

Are you sure you should be using Post? I thought this was for sending form data. Are you able to use Get instead?
 
It is for Amazon, and they specify you must do an HTTPS Post with three "Headers". One of the "headers" is an HTTP parameter: Content-Type. Another "header" is a cookie that they specify and the third one is another HTTP parameter: Authorization. However, rather than just let you put in your username and password to the HTTP component, Amazon insists on you putting it into the form username:password and then doing a base64 encode on it.

If you would like to see the Amazon specification, it is at
I was even thinking about just putting the three "headers" into the HTTP.Request RawData parameter hoping by just doing a Post with no arguments that magically the data would get sent as "headers", but I haven't tried that yet.

You gave me the code for getting HTTP to HTTPS about a month ago, and I really appreciated that... just trying to get it all together to make it work with Amazon.

I liked D6, but D7 is nicer. I bought D2006 a few years ago and all the third party stuff to go with it (about a grand for everything) but D2006 just added too much to the development effort. But, the D7 bugs and limitations are beginning to wear me down so I bought D2010 yesterday. When it arrives, I hope it has a better interface than D2006. Do you need a slightly used D2006 Professional package?
 
:) thanks for the offer. I've tried the trial versions of the D200x and found them way too cluttered. So much of the screen is devoted to non-coding activity. Maybe if I had a 24" LCD screen it would be easier to use.... I'm quite happy with D6.

As far as I can see, you should be adding your info to the TidHTTP.Request property structure.
 
I'll go ahead and try that. Nothing to lose... I just have had other fires to put out for the last 24 hours.
 
Here is the latest:

procedure THTTPSForm.SendBtnClick(Sender: TObject);
var Headers: TStrings;
begin
Headers := TStringList.Create;
Headers.Add(Cookie.Text);
IdSSLIOHandlerSocket1.SSLOptions.Method := TIdSSLVersion(sslvSSLv23);
IdSSLIOHandlerSocket1.SSLOptions.RootCertFile := 'ssl_cert.pem';
HTTPS.IOHandler := IdSSLIOHandlerSocket1;
HTTPS.Request.Username := 'MyUserName';
HTTPS.Request.Password := 'MyPassword';
HTTPS.Request.BasicAuthentication := true;
HTTPS.Request.ContentType := 'text/html';
HTTPS.Port := 443;
HTTPS.Post(URL.Text, Headers);

but this code gets an error saying it cannot find VSINIT.DLL. That DLL apparently belongs to a thing called
Zone Alarm, which I cannot find nor do I think I need.

So, I am getting closer, but no cigar!


 
weird. Perhaps the libeay32.dll and ssleay32.dll files were originally compiled for use with ZoneAlarm?

I would try to find alternative copies of these files. Try here: which is linked to from openssl.org

I downloaded the first link - the Light version, installed everything to c:\openssl (ignored the warning about MSVC8++ not being installed), and then found these two DLLs in the bin folder.

Try with those versions and see if it makes any difference.
 
Great call!

That got past the error and on to the next one, EldOSSLCouldNotLoadSSLLibrary with message 'Could not load SSL Library'. Any ideas there?
 
I'm pretty sure I've seen this as well, and I got around it by using, yet another set of DLLs. I'm pretty sure the ones I'm using at the moment I got from FileZilla. You're welcome to download that, install, and extract the DLLs, or just use the versions I'm using from here
See if they work for you.
 
Thanks, I tried the ones you linked to. Got the same error as last time.
 
Did I need to complete the installation of the download from Shining Light? Do I need to have OpenSSL installed on my system? All I did was pull the two DLLs from the download.
 
I'm pretty sure you just need to pull the two DLLs from the package.

I can't think of anything else to get past this exception. It would seem that Indy cannot load the two DLLs, either because they do not match what Indy is expecting, or because Indy cannot find them. Having them in the same folder as the .exe should be enough.

At this point I would recommend again upgrading to Indy 10.
 
forgive me for butting in, but a full 'build' rather than just 'compile' can often make a difference...

Roo
Delphi Rules!
 
Thanks, roo0047. Don't mind you butting in at all. Tried the full build as you suggested, but no improvement. I have D2006 which has a later version (maybe 10) of Indy. I intend to try that tonight after I reinstall D2006. I just got D2010, but haven't gotten it to install correctly yet (it can't seem to get the help files installed correctly).

I am thinking that Indy9 with my D7 is so old that it may never work. I found out they are still improving Indy 9 so there must have been a lot of changes since 2002 or so.

So, that is my next attempt. I would love to try 2010, but can't complain to Embarcardo because there support computers are still down, so I will just try D2006 and see if anything changes there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top