无法向symfony 1.4应用程序发送PHP cURL请求
我有一个旧的symfony1.4应用程序,现在我想通过PHP和cURL实现远程登录和一些操作调用。问题是,用户似乎没有登录其他操作调用,并且我总是从操作(登录操作除外)中得到响应,用户名和/或密码错误,这类似于“未登录”。这两个cURL请求都是从同一个域(用于测试)从同一个独立的php脚本发出的。 与邮递员一个接一个地调用这两个动作效果相当好 如果你能帮助我,我将不胜感激。以下是我的登录代码:无法向symfony 1.4应用程序发送PHP cURL请求,php,symfony,curl,Php,Symfony,Curl,我有一个旧的symfony1.4应用程序,现在我想通过PHP和cURL实现远程登录和一些操作调用。问题是,用户似乎没有登录其他操作调用,并且我总是从操作(登录操作除外)中得到响应,用户名和/或密码错误,这类似于“未登录”。这两个cURL请求都是从同一个域(用于测试)从同一个独立的php脚本发出的。 与邮递员一个接一个地调用这两个动作效果相当好 如果你能帮助我,我将不胜感激。以下是我的登录代码: $strCookieFilePath = __DIR__."/cookie.txt&quo
$strCookieFilePath = __DIR__."/cookie.txt";
$curlHandle = curl_init();
$strBodyJson = json_encode(array('login_token' => '...'));
$arrOptions = array(
CURLOPT_URL => 'https://url_to_web.app/my_login_app/login/index',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $strBodyJson,
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Content-Length: ' . strlen($strBodyJson)
)
);
curl_setopt_array(
$curlHandle,
$arrOptions
);
$strResponse = curl_exec($curlHandle);
echo $response . '<br />';
$strError = null;
if (curl_errno($curlHandle)) {
echo = curl_error($curlHandle) . '<br />';
}
curl_close($curlHandle);
$strCookieFilePath=\uuuuu DIR\uuuu.“/cookie.txt”;
$curlHandle=curl_init();
$strBodyJson=json_encode(数组('login_token'=>'…');
$aroptions=数组(
CURLOPT_URL=>'https://url_to_web.app/my_login_app/login/index',
CURLOPT_CUSTOMREQUEST=>“POST”,
CURLOPT_POSTFIELDS=>$strBodyJson,
CURLOPT_VERBOSE=>true,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HTTPHEADER=>数组(
'内容类型:application/json',
“内容长度:”.strlen($strBodyJson)
)
);
curl_setopt_数组(
$curlHandle,
$arrOptions
);
$strResponse=curl\u exec($curlHandle);
回音$response
;
$strError=null;
if(curl_errno($curlHandle)){
echo=curl_错误($curlHandle)。“
”;
}
卷曲关闭($curlHandle);
以下是我通过post cURL请求添加数据的代码:
$strCookieFilePath2 = __DIR__."/cookie2.txt";
$url="https://url_to_web.app/my_web_app/add_data/index";
$postinfo = "value1=...&value2=...&value3=...";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $strCookieFilePath2);
curl_setopt($ch, CURLOPT_COOKIE, "symfony=".$_COOKIE['symfony']);
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
$response = curl_exec($ch);
echo $response.'<br />';
$strError = null;
if (curl_errno($curlHandle)) {
$strError = curl_error($curlHandle);
echo $strError . '<br />';
}
curl_close($curlHandle);
$strCookieFilePath2=\uuuuu DIR\uuuu.'/cookie2.txt”;
$url=”https://url_to_web.app/my_web_app/add_data/index";
$postinfo=“value1=…&value2=…&value3=…”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_头,false);
curl_setopt($ch,CURLOPT_NOBODY,false);
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_COOKIEJAR,$strCookieFilePath2);
curl_setopt($ch,CURLOPT_COOKIE,“symfony=”.$_COOKIE['symfony']);
curl_setopt($ch,CURLOPT_USERAGENT,
“Mozilla/5.0(Windows;U;Windows NT 5.0;en-US;rv:1.7.12)Gecko/20050915 Firefox/1.0.7”);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$_SERVER['REQUEST_URI']);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,“POST”);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postinfo);
$response=curl\u exec($ch);
回显$response.“
”;
$strError=null;
if(curl_errno($curlHandle)){
$strError=curl\u错误($curlHandle);
echo$strError.“
”;
}
卷曲关闭($curlHandle);
提前感谢并致以亲切的问候