curl php return 값...?

-@Naver의 이미지

해당 코드는 c++에서 curl을 이용하여 php파일로 특정 주소를 보내는 코드입니다

여기서 궁금한 것은 php 에서 해당 주소에 대한 처리를 한 후 return값을 보내어

잘 처리가 되었을 경우 1, 잘 처리가 되지 않았을 경우 0으로 반환하여

1과 0의 두 경우에 따른 c++에서 처리 동작을 해주려고 하는데..

php에서 return 값이 들어오는 위치를 모르겠습니다.

혹시 몰라서 res를 출력해 보니 php return값에 상관없이 항상 0이 출력되었습니다..

php의 return 값을 어느 부분에서 받나요?
------------------------------------------------------------------------
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://cafe24아이디/search.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "addr=필요한 주소");
res = curl_easy_perform(curl);
std::cout << "res : " << res << std::endl; // res는 항상 0으로 출력되었음
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
curl_global_cleanup();

익명 사용자의 이미지

php에서 어떻게 값을 "return" 해 주고 있나요?

-@Naver의 이미지

그냥 일반적으로 return '1'; 이런식으로 하고있습니다.

ktd2004의 이미지

libcurl에서 http post 호출 예제

* https://curl.haxx.se/libcurl/c/http-post.html

libcurl에서 http response code 확인 예제

* https://curl.haxx.se/libcurl/c/CURLINFO_RESPONSE_CODE.html

libcurl에서 http 웹페이지 읽기 예제

* https://www.joinc.co.kr/w/Site/Web/documents/UsedCurl

-@Naver의 이미지

c++에서 curl을 이용하여 post로 php에게 데이터를 넘겨준 후,

php에서 해당 데이터를 처리한 후 return 값으로 0이나 1로 주도록 하였습니다.

curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ch); //post로 php파일로 보내기

res = curl_easy_perform(curl);

해당코드를 실행하고 어떻게 php에서 온 return value를 받나여?

찾아보니 response code 실행결과는 항상 500이었으며,콜백함수를 이용하라는데..찾아본 결과 아닌것같습니다.

ktd2004의 이미지

php(http)의 응답(출력)은 다음과 같은 형식으로 구성하셔야 합니다.

* https://ko.wikipedia.org/wiki/HTTP

HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Content-Type: text/html; charset=UTF-8
Content-Encoding: UTF-8
Content-Length: 138
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
ETag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Connection: close
 
<html>
<head>
  <title>An Example Page</title>
</head>
<body>
  Hello World, this is a very simple HTML document.
</body>
</html>
 

서버 응답이 500이라는 건, 에러라는 말입니다.
* 500 Internal Server Error 서버 내부 오류.

서버 응답중에 다음중에서 원하는 것을 얻으시면 됩니다. 물론 php에서 적당한 응답을 주어야겠죠.
* 응답 코드 : "HTTP/1.1 200 OK"
* 응답 바디 : " .... "

댓글 달기

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