{"id":1332,"date":"2014-08-31T09:00:57","date_gmt":"2014-08-31T01:00:57","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=1332"},"modified":"2014-09-02T16:56:59","modified_gmt":"2014-09-02T08:56:59","slug":"vc-mfc-%e5%ae%9e%e7%8e%b0%e7%bd%91%e7%ab%99%e5%8f%91%e5%b8%83%e6%96%87%e7%ab%a0ping%e7%99%be%e5%ba%a6%ef%bc%8c%e5%8a%a0%e5%bf%ab%e6%96%87%e7%ab%a0%e6%94%b6%e5%bd%95","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/1332","title":{"rendered":"vc++-mfc-\u5b9e\u73b0\u7f51\u7ad9\u53d1\u5e03\u6587\u7ae0ping\u767e\u5ea6\uff0c\u52a0\u5feb\u6587\u7ae0\u6536\u5f55"},"content":{"rendered":"

vc++<\/strong>-mfc-\u5b9e\u73b0\u7f51\u7ad9\u53d1\u5e03\u6587\u7ae0ping\u767e\u5ea6<\/strong>\uff0c\u52a0\u5feb\u6587\u7ae0\u6536\u5f55<\/span><\/p>\n

\t\/\/ http \u94fe\u63a5\u53d8\u91cf\r\n\tCHttpConnection * m_http;\r\n\r\n\t\t\tCInternetSession CIS;\r\n\t\t\tCString strPingBaidu;\r\n\t\t\tstrPingBaidu = \"ping.baidu.com\";\r\n\t\t\tCString strPingPath;\r\n\t\t\tstrPingPath = \"ping\/RPC2\";\r\n\t\t\tpdlg->m_http = CIS.GetHttpConnection(strPingBaidu) ;\r\n\r\n\t\t\tCHttpFile * pHttpFile = NULL;\r\n\t\t\t\r\n\t\t\t\/*\r\n\t\t\tCHttpFile* OpenRequest(\r\n\t\t\t\tLPCTSTR pstrVerb,\/\/get or post .A pointer to a string containing the verb to use in the request. If NULL, \"GET\" is used.\r\n\t\t\t\tLPCTSTR pstrObjectName,\/\/\u63d0\u4ea4\u7ad9\u70b9\u5185\u5730\u5740\r\n\t\t\t\tLPCTSTR pstrReferer = NULL,\/\/\u8bf7\u6c42\u53c2\u6570\u5b57\u7b26\u4e32\r\n\t\t\t\tDWORD_PTR dwContext = 1,\/\/\u8fd4\u56de\u72b6\u6001\u7801\r\n\t\t\t\tLPCTSTR* ppstrAcceptTypes = NULL,\/\/\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\r\n\t\t\t\tLPCTSTR pstrVersion = NULL,\/\/A pointer to a string defining the HTTP version. If NULL, \"HTTP\/1.0\" is used.\r\n\t\t\t\tDWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT \r\n\t\t\t\t);\r\n\t\t\t\t*\/\r\n\t\t\tpHttpFile = pdlg->m_http->OpenRequest(CHttpConnection::HTTP_VERB_POST,\r\n\t\t\t\tstrPingPath,\/\/\"test\/test.php\",\r\n\t\t\t\tNULL,\r\n\t\t\t\t1,\r\n\t\t\t\tNULL,\r\n\t\t\t\tNULL,\r\n\t\t\t\tINTERNET_FLAG_EXISTING_CONNECT);\r\n\r\n\t\t\t\/\/\u53d1\u9001header\r\n\r\n\t\t\t\/\/pHttpFile->AddRequestHeaders(\"Content-Type:application\/x-www-form-urlencoded\"); \r\n\t\t\t\/\/pHttpFile->AddRequestHeaders(\"Accept:*\/*\");\r\n\t\t\t\/*\r\n\t\t\tPOST \/ping\/RPC2 HTTP\/1.0\r\n\t\t\tUser-Agent: request\r\n\t\t\tHost: ping.baidu.com\r\n\t\t\tContent-Type: text\/xml\r\n\t\t\tContent-Length: 511\r\n\t\t\t*\/\r\n\t\t\tpHttpFile->AddRequestHeaders(\"POST \/ping\/RPC2 HTTP\/1.0\");\r\n\t\t\tpHttpFile->AddRequestHeaders(\"User-Agent: request\");\r\n\t\t\tpHttpFile->AddRequestHeaders(\"Host: ping.baidu.com\");\r\n\t\t\tpHttpFile->AddRequestHeaders(\"Content-Type: text\/xml\");\r\n\r\n\t\t\t\/\/\u53d1\u9001\u8bf7\u6c42\r\n\t\t\t\r\n\t\t\t\/\/\u8fd9\u4e2a\u662fpost\u7684\r\n\t\t\tCString strBlogName,strBlogIndexURL,strNewArticleURL,strRssURL;\r\n\t\t\tstrBlogName =  pdlg->m_CtrlRequestURLInfo.GetItemText(j,1);\r\n\t\t\tstrBlogIndexURL = pdlg->m_CtrlRequestURLInfo.GetItemText(j,1);\r\n\t\t\tstrNewArticleURL = strURL;\r\n\t\t\tstrRssURL = \"\";\r\n\r\n\t\t\tCString strPost;\r\n\t\t\tstrPost = GetPingCString(strBlogName,strBlogIndexURL,strNewArticleURL,strRssURL);\r\n\t\t\t\/\/strPost = pdlg->GetPingCString(\"d\",\"d\",\"d\",\"d\");\t\/\/post\u7684\u6570\u636e\r\n\t\t\t\/\/strPost = \"sdafdfsadf\";\t\/\/post\u7684\u6570\u636e\r\n\t\t\t\/\/pHttpFile->SendRequest(NULL,0,(LPVOID)(LPCTSTR)strPost,strPost.GetLength()); \t\r\n\t\t\t\r\n\t\t\t\/\/if (pHttpFile->SendRequest(NULL,0,NULL,0))\r\n\t\t\tif(pHttpFile->SendRequest(NULL,0,(LPVOID)(LPCTSTR)strPost,strPost.GetLength()))\r\n\t\t\t{\r\n\t\t\t\t\/\/\u6210\u529f\r\n\t\t\t\tDWORD   retcode; \r\n\t\t\t\tpHttpFile->QueryInfoStatusCode(retcode);\r\n\t\t\t\tCString strReturn;\r\n\t\t\t\tif (retcode == 200)\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/\u4e00\u884c\u4e00\u884c\u7684\u8bfb\u51fa\u6765\r\n\t\t\t\t\tCString strLine;\r\n\t\t\t\t\twhile(pHttpFile->ReadString(strLine))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstrReturn = strReturn + strLine + \"\\n\";\r\n\t\t\t\t\t\r\n\t\t\t\t\t}\r\n\t\t\t\t\tpdlg->AddStatus(strReturn);\r\n\t\t\t\t\t\/\/\u663e\u793a\u51fa\u7ed3\u679c\r\n\t\t\t\t\tif (strReturn.Replace(\"0\",\"ok\")==1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\/\/\u80fd\u66ff\u6362\u4e00\u4e2a\uff0c\u8bf4\u660e\u8fd4\u56de\u7684\u662f0\uff0c\u4e5f\u5c31\u662f\u8bf4\u63d0\u4ea4\u6210\u529f\u4e86\r\n\t\t\t\t\t\tpdlg->m_CtrlBaiduPing.SetItemText(pdlg->m_CtrlBaiduPing.GetItemCount()-1,2,\"\u662f\");\r\n\t\t\t\t\t\tpdlg->AddStatus(\"Ping\u767e\u5ea6\u6210\u529f\");\r\n\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (strReturn.Replace(\"1\",\"ok\")==1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpdlg->AddStatus(\"Ping\u767e\u5ea6\u5931\u8d25\");\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\/\/pdlg->AddStatus(strReturn);\r\n\t\t\t\t\t\/\/AfxMessageBox(strReturn);\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\/\/\u5931\u8d25\r\n\t\t\t\tpdlg->AddStatus(\"send request \u5931\u8d25\");\t\t\r\n\t\t\t}\r\n<\/pre>\n

\u81ea\u5df1\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2a\u51fd\u6570<\/p>\n

CString GetPingCString(CString blogname, CString blogindexurl, CString newarticleurl, CString rssurl)\r\n{\r\n\t\/*\r\n\tPOST \/ping\/RPC2 HTTP\/1.0\r\n\tUser-Agent: request\r\n\tHost: ping.baidu.com\r\n\tContent-Type: text\/xml\r\n\tContent-Length: 511\r\n\tweblogUpdates.extendedPing\u767e\u5ea6\u7684\u7a7a\u95f4http:\/\/hi.baidu.com\/baidu\/http:\/\/baidu.com\/blog\/example.html\r\n\t\thttp:\/\/hi.baidu.com\/baidu\/rss\r\n\t\r\n\t\t\r\n\t\t\r\n\t*\/\r\n\t\r\n CString strReturn;\r\n strReturn = \r\n strReturn = \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\";\r\n strReturn = strReturn + \"<methodCall><methodName>weblogUpdates.extendedPing<\/methodName><params><param><value><string>\" + blogname + \\\r\n \"<\/string><\/value><\/param><param><value><string>\" + blogindexurl + \"<\/string><\/value><\/param><param><value><string>\" + newarticleurl +\\\r\n \"<\/string><\/value><\/param><param><value><string>\" + rssurl + \"<\/string><\/value><\/param><\/params><\/methodCall>\";\r\n return strReturn;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

vc++-mfc-\u5b9e\u73b0\u7f51\u7ad9\u53d1\u5e03\u6587\u7ae0ping\u767e\u5ea6\uff0c\u52a0\u5feb\u6587\u7ae0\u6536\u5f55 \/\/ http \u94fe\u63a5\u53d8\u91cf CHttpConnection * m_http; CInternetSession CIS; CString strPingBaidu; strPingBaidu = “ping.baidu.com”; CString strPingPath; strPingPath = “ping\/RPC2”; pdlg->m_http = CIS.GetHttpConnection(strPingBaidu) ; CHttpFile * pHttpFile = NULL; \/* CHttpFile* OpenR<\/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":[235,144,236],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1332"}],"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=1332"}],"version-history":[{"count":6,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1332\/revisions"}],"predecessor-version":[{"id":1338,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1332\/revisions\/1338"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1332"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}