Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从MFC(MSVC 2008)编写的应用程序中查询基于CGI的Web服务器并处理结果?_C++_Visual Studio 2008_Mfc_Cgi_Client Server - Fatal编程技术网

C++ 如何从MFC(MSVC 2008)编写的应用程序中查询基于CGI的Web服务器并处理结果?

C++ 如何从MFC(MSVC 2008)编写的应用程序中查询基于CGI的Web服务器并处理结果?,c++,visual-studio-2008,mfc,cgi,client-server,C++,Visual Studio 2008,Mfc,Cgi,Client Server,我正在探索用搜索字符串(比如以的形式)查询一个网页的选项,该网页的末端运行一个CGI脚本,并在我的应用程序上显示结果(当然,经过适当的处理)。我的应用程序是用MFC C++编写的,我必须承认我以前从未尝试过任何与网络编程相关的东西。 我想做的事很不可行吗?如果没有,有人能告诉我,为了进行这项工作,我需要哪些资源 谢谢 MFC支持构建Http客户端。有关详细信息,请参见MSDN中的 这也可能有用 CInternetSession internet_session; CHttpConnection

我正在探索用搜索字符串(比如以的形式)查询一个网页的选项,该网页的末端运行一个CGI脚本,并在我的应用程序上显示结果(当然,经过适当的处理)。我的应用程序是用MFC C++编写的,我必须承认我以前从未尝试过任何与网络编程相关的东西。 我想做的事很不可行吗?如果没有,有人能告诉我,为了进行这项工作,我需要哪些资源


谢谢

MFC支持构建Http客户端。有关详细信息,请参见MSDN中的

这也可能有用

CInternetSession internet_session;

CHttpConnection* connection = NULL;
CHttpFile* file = NULL;
TRY {
    connection = internet_session.GetHttpConnection("www.somehost.com", (INTERNET_PORT)80);
    // URI needs to be a relative path here
    file = connection->OpenRequest(CHttpConnection::HTTP_VERB_GET, "/some/file/on/server", NULL, 1, NULL, "HTTP/1.1");
    BOOL send_result = file->SendRequest();
    if (send_result == FALSE) {
        // When can this happen? Only when connection fails between this and the previous call.
        // Need to use ugly MFC exception stuff because OpenRequest et al. use it.
        ::AfxThrowInternetException(internet_session.GetContext());
    }
}
CATCH (CInternetException, e) {
    if (file) {
        file->Close();
    }
    delete connection;
    file = NULL;
    connection = NULL;
}
END_CATCH

if (!file) {
    delete file;
    delete connection;
    return false;
}

DWORD status_code;
file->QueryInfoStatusCode(status_code);
if (status_code != 200) {
    CString result;
    if (status_code == 403) {
        result.Format("Authentication error (HTTP 403)");
    } else if (status_code == 404) {
        result.Format("Object not found (HTTP 404)");
    } else if (status_code == 500) {
        result.Format("Application error: malformed request (HTTP 500)");
    } else {
        result.Format("Got unsupported HTTP status code %d", status_code);
    }
    file->Close();
    delete file;
    delete connection;
    return false;
}