curl로 https에 Posting하기

hwiorb의 이미지

안녕하세요. KLDP에 많은걸을 얻어가는 초보자입니다. ^^;
웹페이지에 로그인하는 프로그램을 만들기 위해, 소켓으로 라이브러리
작성하다가, 그냥 curl로 작업하고 있는 중입니다.
https라는게 상당히 머리아프네요.
---------------------
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://그냥저냥로긴페이지");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, "id=sss&pw=aaa");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
----------------------
이렇게 하면 페이지는 가져옵니다. 그런데 로그인 자체는 안되던데... 따로 post하는 뭐, 그런게 있나요?
단지, post만 한 다음, 페이지를 얻어오면 될것 같은데, 어떻게 해야 할지 모르겠습니다.
조그만 힌트라도 부탁드립니다.

bushi의 이미지

cookie

OTL

hwiorb의 이미지

^^a 쿠키 값을 보내줘야 한다는 말씀이신가요?
아, 헤더랑 쿠키는 저 코드엔 안나와 있지만, 보내주고 있습니다.
(사실, 지금, 다른데에 와있어서, 코드를 복사할 겨를이 없거든요)

스니퍼에 암호화되서 나오길레, Post가 되는지 안되는지가 궁금한거였습니다.
저렇게 보내줬는데도, 로그인이 안되길레 말이죠;;

nil.

bushi의 이미지

https 통신내용을 sniffer 로 긁어봐야 말짱 헛거라고 이미 다른 분들이 말씀해주셨을 텐데요.

curl 이 가져온 페이지 내용을 보면 될텐데,
뭣때문에 암호화된 데이타를 스니핑해놓고 로그인이 됐네 안됐네 고민하십니까 ?
http://kldp.org/node/95902#comment-450054
http://kldp.org/node/96988#comment-454954

OTL

hwiorb의 이미지


에고;; ^^;;
"스니퍼로 봐도 이게 된건지 안된건지 모르겠다는 것" 은
"Post가 된건지 안된건지 모르겠다" 는 의도로 쓴것입니다.

말씀드렸듯이, Post 해봐도, curl이 가져오는 페이지 내용이 똑같은 로그인이 안된
페이지만 얻어올뿐이라서, 말이죠.

curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, "id=sss&pw=aaa");

위와 같이, curl에서 post를 해주면, https에서 값을 제대로 얻어올수 있는건가 물었던 겁니다. ^^;;
제가 질문을 워낙 두서없이 적은듯 해서 죄송합니다. 답변감사드립니다.

nil.

bushi의 이미지

안되는 것을 매뉴얼에 적어놨을 리가 있겠습니까.

kldp.org 의 로그인 과정을 curl 로 해봤고, 절차는 다음과 같았습니다.

http://kldp.org 을 GET 요청하면 HTTP 헤더에 cookie 가 포함되어 날아옵니다.

method 는 POST
action 은 /front-1007?destnation=front-1007
id input의 name 은 "name",
password input 의 name 은 "pass"
인 form이 html 에 적혀있습니다.

http://kldp.org/front-1007?destnation=front-1007 을 POST 요청하면서
name=xxx&pass=xxx , cookie 는 앞에서 받은 cookie 를 집어넣어줍니다.

응답의 HTTP 헤더엔 두번째 cookie 가 포함되어 있고,
Location 이 http://kldp.org/front-1007 로 되어 있습니다.

http://kldp.org/front-1007 을 GET 요청하면서,
바로 앞에서 받은 두번째 cookie 를 집어넣어줍니다.

받은 html 은 로그인 된 후의 페이지였습니다.

OTL

댓글 첨부 파일: 
첨부파일 크기
Plain text icon curltest2.c.txt3.85 KB
hwiorb의 이미지

음, 그렇군요.
사실은 몇몇 홈페이지 로그인은 위와 같이 해결을 했었습니다.

그런데 https 로그인 하는게, 자꾸 안되서, 긴가민가 했었던 거구요.
다시 코드를 짜봐야 겠네요 ^^;;
답변감사드립니다. 꾸벅

nil.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.