[완료] libcurl 관련 질문

qldpfh의 이미지

libcurl을 이용하여 http method를 간단하게 주고받는 어플을 만들려고 합니다...

http://curl.haxx.se/libcurl/
도 찾아보고.. 나름 구글링도 열심히 해보고..햇는데 전혀 감이 안잡히네요.

제가 하려는것은 특정 사이트 "http://curl.haxx.se/"에 GET Method를 보내고

html을 받아 char* 형태로 memory상으로 받아오려고 합니다.. char*형태로 된 html을 가지고

다른걸 할 생각이거든요...

근데 char* 형태로 저장시키는 것 자체가 감이 안옵니다...

  CURL *curl;
  char *str;
 
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/");
 
    str = 서버에서 받은 데이터 본문
  }

이런식으로... 구현할려구 하는데 어떻게 해야할까요?
데이터 본문(html)을 char* 형태로 저장할수 있는 방법이 먼가요..ㅠㅠ

답변 부탁드립니다..

bushi의 이미지

qldpfh의 이미지

답변감사합니다.^^

근데 올려주신 부분의 예제들은 거의 다 본거같은데..

Method를 보낸다음 받은 데이터를 바로 콘솔로 출력해버리는것과

파일로 저장하는것은 봤습니다만... 제가원하던 바로 char*로

저장하는부분은 없는것 같더군요...

죄송한데 만약 있다면...(지나쳤을수 있으니..ㅠㅠ) 어느 쌤플인지 알려주시면 감사하겠습니다.^^

그리고 제가원하는 char*로 바로 받아오는게 없다면.. 없다라고.. 말씀 부탁드립니다.^^

bushi의 이미지

찾아보진 않았습니다.

API 문서(그것도 easy interface 부분)만 대강 ... 함수 몇 개 골라 읽어봤는데,
curl_easy_setopt() 를 사용해서 read callback function 을 지정하고,
curl_easy_perform() 을 호출하는 샘플이나,
반대로 write callback function 을 지정하고,
curl_easy_perform() 을 호출하는 샘플이 없던가요 ?

없을 리가 없을 것 같은데, 만약 없다면 죄송해서... 이거...

덧.

없을까봐 간단하게 만들었습니다. 이렇게하는게 맞는지는 모르겠습니다. 저도 처음이라.

OTL

댓글 첨부 파일: 
첨부파일 크기
Plain text icon curltest.c.txt1.31 KB
qldpfh의 이미지

죄송할것 까지야....

이렇게까지 신경써주시니 감사합니다.^^

많은 도움이 될듯합니다..

좋은정보.. 감사하구요.. 소스 잘쓰겠습니다.^^

chunsj의 이미지

CURLOPT_{WRITE|READ}FUNCTION 옵션을 이용해서 데이터 읽기/쓰기에 대한 callback의 지정이 되는 것 같네요. 이걸 이용해서 char 포인터에 데이터를 채우면 되겠네요.

qldpfh의 이미지

답변 감사합니다.^^
bushi 님께서 주신 예제에도 같은 부분이 있네요..

참조해서 하면 될듯 합니다..^^

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.