Logging in remotely via CURL. Tried many examples, can't get it to work.

I’ve tried many varients of this code:

<?php

$post_str = 'log=joetheater&pwd=joe444&redirect_to=http://mysite.com/wp-admin/&testcookie=1&wp-submit=Log%20In';
$cookie = "cookie.txt";
$url = "http://54.213.79.120/indieXPdev/wp-login.php";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, 'http://54.213.79.120/indieXPdev/wp-admin/');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);

All I get in my result is:

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Apache/2.2.25 (Amazon) Server at 54.213.xx.xxx Port 80
1

I don’t even see anything being written out to cookies.txt. Puzzling….