onLOoker has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, this is extremely urgent so please help me out if you know how... I have a script that register domain names for me. Currently, I have it setup for Enom registrar. It is using IO::Socket::INET. All the data like username, password, registration info are sent through http, port 80.

However, I am trying to modified it to work for another registrar. But that registrar is using https. Therefore, using port 80 won't work. Below is snippets of code for the Enom registrar, where it makes the connection then sends the data across.

new_reg { my ($domain) = @_; my ($domain_name, $tld) = split('\.', $domain); my %state;$state{'Command'} = 'Purchase'; $state{'tld'} = $tld; $state{'sld'} = $domain_name; $state{'responsetype'} = 'text'; $state{'NS1'} = $formdata{'ns1_host'}; $state{'NS2'} = $formdata{'ns2_host'}; $state{'NumYears'} = $formdata{'reg_period'}; $state{'RegistrantFirstName'} = $formdata{'reg_first_name'}; $state{'RegistrantLastName'} = $formdata{'reg_last_name'}; $state{'RegistrantAddress1'} = $formdata{'reg_address1'}; $state{'RegistrantCity'} = $formdata{'reg_city'}; $state{'RegistrantS +tateProvince'} = $formdata{'reg_state'}; $state{'RegistrantPostalCode'} = $formdata{'reg_zipcode'}; $state{'Reg +istrantPhone'} = $formdata{'reg_telephone'}; $state{'RegistrantCountr +y'} = $formdata{'reg_country'}; $state{'UID'} = $username; $state{'PW'} = $password; my $href = build_href($enom_start_url, %state); print("href = $enom_server , $href"); my $result; my $s = IO::Socket::INET->new(PeerAddr => "$enom_server:80") or return + undef; print $s "GET $href HTTP/1.0\n\n"; while (<$s>) { $result .= $_; } close($s); my $outfile = "regout-${domain}.html"; open (REGOUT, ">$outfile") or warn "couldnt write $outfile: $!\n"; print REGOUT "$result\n"; close REGOUT;

Basically, these are the form fields on the Enom domain name page. The data is stored in the text field name then sent across using http, port 80.

But I am trying to change it to support another registrar that uses https, port 443. But I have no luck at all in the getting it to work. Obviously, it won't work connecting using INET, so I modified it to SSL. Below is an example of the modificaiton to the connection part of the code.

my $s = new IO::Socket:SSL("$registrar:https") or die "Couldn't connec +t: err". &IO::Socket::SSL::errstr();
Besides the modified part above, I have edit the form field names and values for the new registrar API. I'm not sure if IO::Socket::SSL sends the data across like IO::Socket::INET.

But I left it alone. Below is an example of the modified fields for the new registrar API. These are the few textfields on the registrar registration page.

$state{'username'} = $username; $state{'password'} = $password;

Can anyone tell me why I can't seem to register a domain name with this setup at this registrar? What am I doing wrong? What needs to be done to get it to work on this registrar? Any help would be appreciated, thanks!

Replies are listed 'Best First'.
Re: Problems with sending data over Socket SSL
by tachyon (Chancellor) on Feb 28, 2004 at 11:08 UTC

    I would strongly suggest using LWP::UserAgent. It you want to do it with raw sockets then you really need to understand the HTTP and SSL protocols in more detail than it appears you do. I would almost certainly expect that an https connection would be using POST for its data, in which case sending it using GET is not going to work.

    If you have a good reason to do it at a lower level then:

    use IO::Socket::SSL 'debug4'; # levels 1-4 available

    Alternatively use LWP

    use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; )"); # Lie + ;-) my $req = new HTTP::Request POST => 'https://wherever.com/register.cgi +'; $req->content_type('application/x-www-form-urlencoded'); $req->content('match=www&errors=0'); my $res = $ua->request($req); print $res->is_success ? $res->content : "Error: ".$res->as_string;

    cheers

    tachyon

      Seeing a pattern yet, OnLooker? They posted this query to other forums and were told (by myself, several times) to use LWP::UserAgent. Kind of like a kid- don't like what dad says? Ask mom.

      This is UNDOUBTEDLY easier to do with LWP::UserAgent. After seeing some of the code you wrote, my suggestion was to start over and ditch your Socket-based stuff. LWP makes web automation that easy.

      -Any sufficiently advanced technology is
      indistinguishable from doubletalk.

      My Biz

      I have written a script with LWP that registers a domain name. But based on that registrar that I'm using, I couldn't figure out how to send my personal information for registration. I could send uername, password, domain name, but not my personal information for the final registration. It's probably due to the submit button written in javascript. The only way to do it is to post it instead of getting it...

      However, I can't seem to make use of the post alone. It only works with getting the webpage, then posting the values. Otherwise, it won't work if used post alone... Is this how LWP works? Get the content then send the data? Below is the script that submits my personal information for registration.

      <input type="image" name="" src="images/btn_purchase.gif" alt="Buy now +" border="0" tabindex="16" onclick="return checkKey('success');">
      As you can see, the onclick, submits it. I'm guessing that if I use post, I won't have to worry about submitting it. It will automatically submit it. Am I correct. Thanks.
        hi. well, can you actually show us the javascript data... maybe this script is setting an addional field or does other fancy stuff before it ist posting the data to the server.
Re: Problems with sending data over Socket SSL
by matija (Priest) on Feb 28, 2004 at 08:15 UTC
    You should look at the return values from IO::Socket::SSL to see if you are getting any error messages from the socket layer.

    If the connection works OK, read from the socket to see what messages the registrar is sending you back. If the fields have errors in them, maybe the registrar is sending you an error message.