{"id":1529,"date":"2016-05-22T13:05:19","date_gmt":"2016-05-22T05:05:19","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=1529"},"modified":"2022-06-30T17:26:05","modified_gmt":"2022-06-30T09:26:05","slug":"vc-curl%e5%8f%96%e5%be%97%e7%bd%91%e9%a1%b5html%e6%96%87%e4%bb%b6%e5%86%85%e5%ae%b9%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/1529","title":{"rendered":"vc++ curl\u53d6\u5f97\u7f51\u9875html\u6587\u4ef6\u5185\u5bb9\u7684\u65b9\u6cd5"},"content":{"rendered":"

\u9996\u5148\u5c31\u662f\u4e00\u4e2a\u56de\u8c03\u51fd\u6570<\/p>\n

static size_t getResponseString(void *ptr, size_t size, size_t nmemb, void *userdata)\n{\/\/\u53c2\u6570userdata\u662f\u5b58\u653e\u6570\u636e\u7684\u6307\u9488 \u5176\u4ed6\u4e09\u4e2a\u83b7\u53d6\u5185\u5bb9\nstd::string *version = (std::string*)userdata;\nversion->append((char*)ptr, size * nmemb);\n\nreturn (size * nmemb);\n}<\/pre>\n

\u7136\u540e\u5c31\u662f\u4e00\u4e2acurl \u8bf7\u6c42\u00a0<\/p>\n\n\n

curl_global_init(CURL_GLOBAL_WIN32); \nCURL *easy_handle = curl_easy_init(); \ncurl_httppost *post = NULL; curl_httppost *last = NULL; \ncurl_formadd(&post, &last, CURLFORM_COPYNAME, \"school_id\", CURLFORM_COPYCONTENTS, IntToCString(pMain->m_nSchoolID), CURLFORM_END); \ncurl_formadd(&post, &last, CURLFORM_COPYNAME, \"exam_id\", CURLFORM_COPYCONTENTS, IntToCString(pExam->m_nExamID), CURLFORM_END); \ncurl_formadd(&post, &last, CURLFORM_COPYNAME, \"key\", CURLFORM_COPYCONTENTS, pMain->m_sDataKey, CURLFORM_END); \ncurl_easy_setopt(easy_handle, CURLOPT_URL, \"http:\/\/www.xx.com\/nn\/\" + pMain->m_sCustomerCode + \"\/client\/school-sheet-upload\" ); \nstd::string szbuffer; \ncurl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, getResponseString); \ncurl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, &szbuffer); \/\/curl_easy_setopt(easy_handle, CURLOPT_HTTPGET, post); curl_easy_setopt(easy_handle, CURLOPT_HTTPPOST, post); \nint nResult = curl_easy_perform(easy_handle); \nlong http_code = 0; curl_easy_getinfo (easy_handle, CURLINFO_RESPONSE_CODE, &http_code); \ncurl_formfree(post); \ncurl_easy_cleanup(easy_handle); \ncurl_global_cleanup(); \nCString strText = szbuffer.c_str(); \nstrText = Utf_8ToUnicode(strText.GetBuffer(0)); \n\/\/WriteLog(strText,\"res.html\"); \nif (strText == \"1\") {\n ( (CButton*)GetDlgItem(IDC_CHECK_SCHOOL_SHEET_UPLOAD))->SetCheck(TRUE); \n} \nelse if ( strText == \"0\" ) { \n( (CButton*)GetDlgItem(IDC_CHECK_SCHOOL_SHEET_UPLOAD))->SetCheck(FALSE); \n}<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u9996\u5148\u5c31\u662f\u4e00\u4e2a\u56de\u8c03\u51fd\u6570 static size_t getResponseString(void *ptr, size_t size, size_t nmemb, void *userdata) {\/\/\u53c2\u6570userdata\u662f\u5b58\u653e\u6570\u636e\u7684\u6307\u9488 \u5176\u4ed6\u4e09\u4e2a\u83b7\u53d6\u5185\u5bb9 std::string *version = (std::string*)userdata; version->append((char*)ptr, size * nmemb); return (size * nmemb); } \u7136\u540e\u5c31\u662f\u4e00\u4e2acurl \u8bf7\u6c42\u00a0 curl_global_init(CURL_GLOBAL_WIN32); CU<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,219,9],"tags":[264],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1529"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1529"}],"version-history":[{"count":7,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1529\/revisions"}],"predecessor-version":[{"id":2006,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1529\/revisions\/2006"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1529"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}