2013-02-14 2 views
0

데이터베이스에 삽입을 수행하기 위해 웹 서버에서 PHP 스크립트를 실행하고 있습니다. 이 스크립트는 암호화 된 데이터를 수신하고 해독 한 다음 db로 푸시합니다.C++ 프로그램에서 PHP 웹 서버로 데이터 보내기

이 데이터를 보내는 책임은 Linux에서 실행되는 C++ 프로그램으로,이 프로그램은 5 초마다 40 문자 이하의 메시지를 보냅니다.

URL (http://myserver.com/myscript.php?message=adfafdadfasfasdfasdf)을 열고 인수로 메시지를받는 bash 스크립트를 호출하려고 생각했습니다.

복잡한 솔루션이 필요하지 않습니다. 단지 URL을 열어야하기 때문에 단방향 통신 채널입니다.

몇 가지 간단한 해결책이 있나요?

감사합니다.

+0

귀하의 솔루션은 제약 조건을 고려할 때 합당한 것처럼 보입니다. – mkaatman

답변

3

보다 강력한 솔루션은 libcurl을 사용하는 것이므로 open a http connection in a few lines이 될 수 있습니다. 다음 링크에서 자체 포함 된 예는 다음과 같습니다 당신이 HTTP 쿼리의 결과를 분석 할 필요가 없기 때문에, 당신은 단지 wget 같은 표준 유틸리티를 호출 할 system를 사용할 수

#include <stdio.h> 
#include <curl/curl.h> 

int main(void) 
{ 
    CURL *curl; 
    CURLcode res; 

    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); 
    /* example.com is redirected, so we tell libcurl to follow redirection */ 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl); 
    /* Check for errors */ 
    if(res != CURLE_OK) 
     fprintf(stderr, "curl_easy_perform() failed: %s\n", 
       curl_easy_strerror(res)); 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 
    return 0; 
} 
1

.

int retVal = system("wget -O- -q http://whatever.com/foo/bar"); 
// handle return value as per the system man page 

이것은 기본적으로 스크립트의 간접 저장에 대해 생각하고 있었는지와 동일합니다.

+0

답변 해 주셔서 감사합니다. 마침내 libcurl을 사용하기로 결심했다. – user1370912

관련 문제