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

I’ve tried many varients of this code:


$post_str = 'log=joetheater&pwd=joe444&redirect_to=http://mysite.com/wp-admin/&testcookie=1&wp-submit=Log%20In';
$cookie = "cookie.txt";
$url = "";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, '');
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;

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

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