WindowsのMFC HTTPのGETリクエスト機能プロセス
1のCString m_strHttpUrl(_T(" http://10.200.80.86:8090/course/upload " )) 2 CInternetSession * pInternetSession = NULL; 3 CHttpConnection * pHttpConnection = NULL; 4 CHttpFile * pHttpFile = NULL; 5 6 7 // 建立连接 8 pInternetSession = 新しいCInternetSession(AfxGetAppName())。 9 10 11 のCString strServer。 12 CStringのstrObject。 13 DWORD dwServiceType。 14 INTERNET_PORT nPortに。 15 AfxParseURL(m_strHttpUrl、dwServiceType、strServer、strObject、nPortに)。 16 17 18 試みる 19 { 20 pHttpConnection = pInternetSession-> GetHttpConnection(strServer、nPortにします)。 21 } 22 キャッチ(CInternetExceptionの*のE) 23 { 24 のCString STRERROR。 25 strError.Format(_T(" GetHttpConnectionエラー:%U、コンテキスト:%U ")、E-> m_dwError、E-> m_dwContext)。 26 AfxMessageBox(STRERROR)。 27 28 もし(NULL!= pHttpConnection) 29 { 30 pHttpConnection-> クローズ(); 31 削除pHttpConnectionを。 32 pHttpConnection = NULL; 33 } 34 であれば(NULL =!pInternetSession) 35 { 36 pInternetSession-> クローズ(); 37 削除pInternetSessionを。 38 pInternetSession = NULL; 39 } 40 41 リターンFALSE。 42 } 43 44 45 strParam.Format(_T(" ?ccvid =%S&名=%S&ファイルサイズ=%U&第= 1&形式=%S&MD5 =%S&たServiceType =%S&UID =%S&時間=%I64u " )、 46 m_strVideoid、m_strVideoName、m_fileLen、g_strFormat、m_strFileMD5、m_strServicetype、m_strUserid、CURRENTTIME)。 47 strParam.AppendFormat(_T(" ハッシュ=%のS&" )、sHash.c_str())。 48 49 CStringのstrTempObject = strObject + strParam。 50 pHttpFile = pHttpConnection-> OpenRequest(CHttpConnection :: HTTP_VERB_GET、strTempObject)。 OpenRequestエラー。" )); 54 55 であれば(NULL =!pHttpFile) 56 { 57 pHttpFile-> クローズ(); 58 削除pHttpFile; 59 pHttpFile = NULL; 60 } 61 なら!(NULL = pHttpConnection) 62 { 63 pHttpConnection-> 閉じます( ); 64 、削除pHttpConnection; 65 pHttpConnection = NULL; 66 } 67 であれば NULL(=!pInternetSession) 68 { 69 pInternetSession-> ()を閉じます。 70 削除pInternetSessionを。 71 pInternetSession = NULL; 72 } 73 74 リターンFALSE。 75 } 76 77 78 pHttpFile-> AddRequestHeaders(_T(" コンテンツタイプ:application / x-www-form-urlencodedで;のcharset = UTF-8 " )); 79 80 81 試みる 82 { 83 pHttpFile-> のsendRequest(); 84 } 85 キャッチ(CInternetException * E) 86 { 87 のCString STRERROR。 88 strError.Format(_T(" のsendRequestエラー:%U、コンテキスト:%U ")、E-> m_dwError、E-> m_dwContext); 89 AfxMessageBox(STRERROR)。 90 91 であれば(NULL =!pHttpFile) 92 { 93 pHttpFile-> クローズ(); 94 削除pHttpFileを。 95 pHttpFile = NULL; 96 } 97 であれば(NULL!= pHttpConnection) 98 { 99 pHttpConnection-> クローズ(); 100 削除pHttpConnection。 101 pHttpConnection = NULL; 102 } 103 であれば(!= NULL pInternetSession) 104 { 105 pInternetSession-> クローズ(); 106は 削除pInternetSessionと、 107 pInternetSession = NULL; 108 } 109 110 戻りFALSE。 111 } 112 113 114 CHAR szChars [1024 + 1 ] = { 0 }。 115 CStringのstrRawResponse。 116 UINT nReaded = 0 。 117 一方((nReaded = pHttpFile->読む((ボイド *)szChars、1024))> 0 ) 118 { 119 szChars [nReaded] = ' \ 0 ' 。 120 strRawResponse + = szChars。 121 のmemset(szChars、0、1024 + 1 )。 122 } 123 124 AfxMessageBox(strRawResponse)。 125 126 127 もし(NULL =!pHttpFile) 128 { 129 pHttpFile-> クローズ(); 130は 削除pHttpFileを。 131 pHttpFile = NULL; 132 } 133 であれば(!= NULL pHttpConnection) 134 { 135 pHttpConnection-> クローズ(); 136 削除pHttpConnection。 137 pHttpConnection = NULL; 138 } 139 であれば(NULL!= pInternetSession) 140 { 141 pInternetSession-> )(閉じます。 142は 削除pInternetSessionと、 143 pInternetSession = NULL; 144 } 145 146 リターン TRUE。