Jump to content

CURL POST Problem


sastro

Recommended Posts

Here is my code and it doesn't work

 

<?php
$br='Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11';
$ref='https://mydomain:9999/main.do';
$url='https://mydomain/j_security_check';
$var='j_username=username&j_password=username';

$ch = curl_init();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_POST, 2);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $var);
curl_setopt($ch, CURLOPT_USERAGENT, $br);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
if(file_exists('D:/www/dp/autoemail/login.txt')){
  curl_setopt($ch, CURLOPT_COOKIEFILE, 'D:/www/dp/autoemail/login.txt');
}else{
curl_setopt($ch, CURLOPT_COOKIEJAR, 'D:/www/dp/autoemail/login.txt');
}

$store = curl_exec ($ch);
echo $store;
curl_close($ch);
?>

Link to comment
https://forums.phpfreaks.com/topic/186114-curl-post-problem/#findComment-982913
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.