1
나는 내 웹 사이트에 로그인하는 간단한 코드를 만들었습니다. CURL 게시물 길이 필요
private function request($url, $reset_cookies, $post_data)
{
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 0,
CURLOPT_FAILONERROR => 1,
CURLOPT_USERAGENT => $this->user_agent,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_MAXREDIRS => 10,
CURLOPT_AUTOREFERER => 1,
CURLOPT_COOKIESESSION => $reset_cookies ? 1 : 0,
CURLOPT_COOKIEJAR => $this->session_id,
CURLOPT_COOKIEFILE => $this->session_id,
);
// Add POST data
if (isset($post_data))
{
$options[CURLOPT_CUSTOMREQUEST] = 'POST';
$options[CURLOPT_POST] = 1;
$options[CURLOPT_POSTFIELDS] = http_build_query($post_data);
}
// Attach options
curl_setopt_array($this->curl, $options);
// Execute the request and read the response
$content = curl_exec($this->curl);
// Handle any error
if (curl_errno($this->curl)) throw new Exception(curl_error($this->curl));
return $content;
}
그래서 기본적으로 내 로그인 시스템을위한 일반적인 단계는 다음과 같습니다
가 보안 토큰을 검색하고 쿠키 세션을 초기화하는 GET 요청을 보냅니다.
$security_token = $this->browser->request('https://mysite.com/login', true, null);
사용자 이름, 암호 및 보안 토큰과 POST 요청을 보내기 (DONE과 WORKING). 단계 # 2에
$postdata = array(
'login' => $login,
'password' => $password,
'__RequestVerificationToken' => $security_token,
);
$login_page = $this->browser->request('https://mysite.com/login', false, $postdata);
, 나는 콘텐츠 길이가 필요 말하는 411 오류가 발생했습니다.
잘못된 것이 있습니까? 아니면 매개 변수를 설정하는 것을 잊었습니까?
당신이 봤어이 줄을 제거했다 : http://stackoverflow.com/search?q=curl+required+length+is%3Aquestion – Mike
@ 마이크 그래, 난 이미했습니다 그 페이지들을 읽으십시오. 어떤 해결책도 찾지 못했습니다 – Manitoba
두 개의 요청에 대해 동일한 Curl 인스턴스를 사용하고 있다는 사실을 잊어 버렸습니다. * – Manitoba