Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

cURL with Perl

Question posted by: rottmanj (Newbie) on May 6th, 2008 06:16 PM
I am working on a revamp of a previous application that I have written in coldfusion. The application deals with RETS data. The issue that I am having is with using the curl option HTTP_AUTH and CURLAUTH_DIGEST.

When attempting to authenticate against the server. No matter what I try, my authentication always fails. I have made sure to validate the auth information.

In my testings, I have also verified that curl can authenticate via the command line option.

Here is my current testing code base.

Expand|Select|Wrap|Line Numbers
  1.  
  2. my $curl= new WWW::Curl::easy;
  3. $curl->setopt(CURLOPT_VERBOSE,1); 
  4. $curl->setopt(CURLOPT_HTTPAUTH,CURLAUTH_ANY);  
  5. $curl->setopt(CURLOPT_USERPWD, '$user:$pass'); 
  6. $curl->setopt(CURLOPT_URL, $site);
  7. my $retcode = $curl->perform;
  8.  
  9. print $retcode;



This is the error I receive back.

< HTTP/1.1 401 Unauthorized
HTTP/1.1 401 Unauthorized
< Content-Length: 1944
Content-Length: 1944
< Content-Type: text/html
Content-Type: text/html
< Server: Microsoft-IIS/6.0
Server: Microsoft-IIS/6.0
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
< Date: Tue, 06 May 2008 18:13:40 GMT
Date: Tue, 06 May 2008 18:13:40 GMT
< Connection: close
Connection: close
numberwhun's Avatar
numberwhun
Forum Leader
2,007 Posts
May 6th, 2008
06:33 PM
#2

Re: cURL with Perl
Quote:
I am working on a revamp of a previous application that I have written in coldfusion. The application deals with RETS data. The issue that I am having is with using the curl option HTTP_AUTH and CURLAUTH_DIGEST.

When attempting to authenticate against the server. No matter what I try, my authentication always fails. I have made sure to validate the auth information.

In my testings, I have also verified that curl can authenticate via the command line option.

Here is my current testing code base.

Expand|Select|Wrap|Line Numbers
  1.  
  2. my $curl= new WWW::Curl::easy;
  3. $curl->setopt(CURLOPT_VERBOSE,1); 
  4. $curl->setopt(CURLOPT_HTTPAUTH,CURLAUTH_ANY);  
  5. $curl->setopt(CURLOPT_USERPWD, '$user:$pass'); 
  6. $curl->setopt(CURLOPT_URL, $site);
  7. my $retcode = $curl->perform;
  8.  
  9. print $retcode;



This is the error I receive back.

< HTTP/1.1 401 Unauthorized
HTTP/1.1 401 Unauthorized
< Content-Length: 1944
Content-Length: 1944
< Content-Type: text/html
Content-Type: text/html
< Server: Microsoft-IIS/6.0
Server: Microsoft-IIS/6.0
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
< Date: Tue, 06 May 2008 18:13:40 GMT
Date: Tue, 06 May 2008 18:13:40 GMT
< Connection: close
Connection: close


I would check, without using your script, that you can log into the website first. The error "Unauthorized" is telling me you cannot.

Regards,

Jeff

Reply
rottmanj's Avatar
rottmanj
Newbie
11 Posts
May 6th, 2008
06:56 PM
#3

Re: cURL with Perl
I have already verified that I am able to log in. The Unauthorized is part of the ResponseHeaders that I receive back.

Reply
nithinpes's Avatar
nithinpes
Expert
290 Posts
May 7th, 2008
05:16 AM
#4

Re: cURL with Perl
Quote:
I am working on a revamp of a previous application that I have written in coldfusion. The application deals with RETS data. The issue that I am having is with using the curl option HTTP_AUTH and CURLAUTH_DIGEST.

When attempting to authenticate against the server. No matter what I try, my authentication always fails. I have made sure to validate the auth information.

In my testings, I have also verified that curl can authenticate via the command line option.

Here is my current testing code base.

Expand|Select|Wrap|Line Numbers
  1.  
  2. my $curl= new WWW::Curl::easy;
  3. $curl->setopt(CURLOPT_VERBOSE,1); 
  4. $curl->setopt(CURLOPT_HTTPAUTH,CURLAUTH_ANY);  
  5. $curl->setopt(CURLOPT_USERPWD, '$user:$pass'); 
  6. $curl->setopt(CURLOPT_URL, $site);
  7. my $retcode = $curl->perform;
  8.  
  9. print $retcode;



This is the error I receive back.

< HTTP/1.1 401 Unauthorized
HTTP/1.1 401 Unauthorized
< Content-Length: 1944
Content-Length: 1944
< Content-Type: text/html
Content-Type: text/html
< Server: Microsoft-IIS/6.0
Server: Microsoft-IIS/6.0
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="343baa915fcdf513c28822dd5e99f683",opaque="060518134015940"
< Date: Tue, 06 May 2008 18:13:40 GMT
Date: Tue, 06 May 2008 18:13:40 GMT
< Connection: close
Connection: close


Using single quotes around variables will block the substitution of those variables(will be considered literal string). Change:
Expand|Select|Wrap|Line Numbers
  1. $curl->setopt(CURLOPT_USERPWD, '$user:$pass'); 


to

Expand|Select|Wrap|Line Numbers
  1. $curl->setopt(CURLOPT_USERPWD, "$user:$pass"); 


That's how this line should be, though this may/may not solve your issue.

Reply
rottmanj's Avatar
rottmanj
Newbie
11 Posts
May 14th, 2008
09:26 PM
#5

Re: cURL with Perl
I am having a heck of a time getting this to work. Every example that I have found uses pretty much what I have here.

At first glance it looks like it is trying to use Basic auth, but I know for a fact that this server uses digest auth.

As I have said before.

Verified that server uses Digest auth
Verified username and password
Verified that URI
Tried with '$user:$pass' and "$user:$pass"

Any help with this would be greatly appreciated.

Here is the output that I get from my app.

Expand|Select|Wrap|Line Numbers
  1. About to connect() to rets.armls.mlsrets.com port 80 (#0)
  2.   Trying 65.83.83.235... connected
  3. Connected to rets.armls.mlsrets.com (65.83.83.235) port 80 (#0)
  4. Server auth using Basic with user '*********'
  5. GET /rets/login HTTP/1.1
  6. Authorization: Basic Q1JJTDAxOkpuITIzQA==
  7. Host: rets.armls.mlsrets.com
  8. Accept: */*
  9.  
  10.  
  11. HTTP/1.1 401 Unauthorized
  12. HTTP/1.1 401 Unauthorized
  13. Content-Length: 1944
  14. Content-Length: 1944
  15. Content-Type: text/html
  16. Content-Type: text/html
  17. Server: Microsoft-IIS/6.0
  18. Server: Microsoft-IIS/6.0
  19. X-Powered-By: ASP.NET
  20. X-Powered-By: ASP.NET
  21. WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="44722adb40435c5b13ac90bd5704d271",opaque="14052119422857"
  22. WWW-Authenticate: Digest qop="auth",realm="rets@marketlinx.com",nonce="44722adb40435c5b13ac90bd5704d271",opaque="14052119422857"
  23. Date: Wed, 14 May 2008 21:19:41 GMT
  24. Date: Wed, 14 May 2008 21:19:41 GMT
  25. Connection: close
  26. Connection: close

Last edited by eWish : May 14th, 2008 at 10:59 PM. Reason: Please use code tags for data as well
Reply
Reply
Not the answer you were looking for? Post your question . . .
189,161 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Perl Forum Contributors