</head> <form method="post" action="the URL of POST" > <p> <textarea cols="80" rows="20"></textarea> </p> <p> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </p> </form> </html> //--------------------------------------------------------------------- |
||||||||||||||||
gjd111686(數字金剛) 於 2004-7-5 10:48:17 | ||||||||||||||||
{ iAmount=0; iMsgAmount=0; iFileAmount=0; CInternetSession m_Session("DigitalTitan"); CHttpConnection* pServer=NULL; CHttpFile* pFile=NULL; CHttpFile* pTaskFile=NULL; CString strServerName=strServerIP; INTERNET_PORT nPort=(INTERNET_PORT)atoi(strServerPort); CString strURL=strLoginAddress; try { pServer=m_Session.GetHttpConnection(strServerName,nPort); pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strURL,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT); CString strHeaders=_T("Content-Type: application/x-www-form-urlencoded"); CString strFormData; strFormData.Format("UserName=%s&Password=%s&action=submit",strLoginUserName,strLoginPassword); //AfxMessageBox(strFormData,MB_ICONINFORMATION); if(pFile->SendRequest(strHeaders,(LPVOID)(LPCTSTR)strFormData,strFormData.GetLength())==0) { //AfxMessageBox("網絡異常...",MB_ICONINFORMATION); pFile->Close(); delete pFile; pServer->Close(); delete pServer; m_Session.Close(); } else { pFile->ReadString(strInfo); if(strInfo.Find("Apache Tomcat/4.1.18 - Error report",0)!=-1) { AfxMessageBox("服務器產生錯誤.",MB_ICONINFORMATION); return 0; } pFile->Close(); delete pFile; pServer->Close(); delete pServer; pTaskFile=(CHttpFile*)m_Session.OpenURL(strLoginDataAddress); CString strBuf; CString strText; while(pTaskFile->ReadString(strText)) { strBuf+="\r\n"; strBuf+=strText; } pTaskFile->Close(); delete pTaskFile; m_Session.Close(); //AfxMessageBox(strBuf,MB_ICONINFORMATION); int iBegin,iEnd; iBegin=0;iEnd=0; CString strTemp; strTemp=""; //信息提取 //關鍵字一 iBegin=strBuf.Find("更多方案",0); if(iBegin!=-1) { //關鍵字二 iEnd=strBuf.Find("已辦理方案</font>",iBegin); strTemp=strBuf.Mid(iBegin+9,iEnd-(iBegin+9)); strTemp.MakeLower(); //分隔符 int iResult=strTemp.Find("<tr",0); if(iResult==-1) { // } else if(iResult<strTemp.GetLength()) { while(iResult!=-1) { iAmount++; iResult=strTemp.Find("<tr",iResult+3); } //修正結果 iAmount=iAmount-5; } } //另關鍵字:新申請(3)新歸檔方案(0) iBegin=strBuf.Find("新申請(",0); iEnd=strBuf.Find(")",iBegin); strTemp=strBuf.Mid(iBegin+9,iEnd-(iBegin+9)); iMsgAmount=atoi(strTemp); iBegin=strBuf.Find("新歸檔方案(",0); iEnd=strBuf.Find(")",iBegin); strTemp=strBuf.Mid(iBegin+13,iEnd-(iBegin+13)); iFileAmount=atoi(strTemp); } } catch(CInternetException* e) { char strErrorBuf[255]; e->GetErrorMessage(strErrorBuf,255,NULL); AfxMessageBox(strErrorBuf,MB_ICONINFORMATION); pFile=NULL; delete pFile; pTaskFile=NULL; delete pTaskFile; pServer=NULL; delete pServer; m_Session.Close(); return 0; } return iAmount; } |
||||||||||||||||
gjd111686(數字金剛) 於 2004-7-5 10:51:10 | ||||||||||||||||
char header[]= "Accept: */*\r\n" "Accept-Language: zh-cn\r\n" "Accept-Encoding: gzip, deflate\r\n" "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)\r\n" "Host: www.csdn.net\r\n" "Connection: Keep-Alive\r\n" "Cookie: ASPSESSIONIDCCABSCAD=JACFBJLDAKFIELKFCHFDNPHN;\r\n" "ABCDEF=oiUCTNhlXF62fTpukWOwMLcxxLpFecMSPdKZ7YtPqkg372acN2Wz4A%25253d%25253d;\r\n" "QWERTOP=1399; userid=379347; daynum=0\r\n" "\r\n"; res=send(sock, request,strlen(request),0); res=send(sock, header,strlen(header),0); |
||||||||||||||||
wu_chang(無常來去) 於 2004-7-5 11:22:00 | ||||||||||||||||
繼續等待中。。。。。。 |
||||||||||||||||
gjd111686(數字金剛) 於 2004-7-5 18:15:16 | ||||||||||||||||
newkey007(無限天空 www.xDrv.com) 於 2004-7-5 18:27:43 | kugou123(酷狗)(http://www.xiaozhou.net) 於 2004-7-5 22:50:30 | * 輸入參數: TCHAR* hdrs - HTTP頭 TCHAR* accept - Accept類型 TCHAR* Method - POST 或 GET TCHAR* frmdata - 要提交的數據 TCHAR* ServerName - 服務器地址 TCHAR* FormAction - 數據提交到的網頁名稱 * 輸出參數: 無 * 返 回 值: int - 返回操作狀態(見MSDN) *****************************************************************/ |
kugou123(酷狗)(http://www.xiaozhou.net) 於 2004-7-5 22:52:05 | { // 創建Internet HINTERNET hSession = InternetOpen("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (!hSession) { return 5; } // 連接服務器 HINTERNET hConnect = InternetConnect(hSession, ServerName, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1); if (!hConnect) { return 2; } // 創建一個請求 HINTERNET hRequest = HttpOpenRequest(hConnect, Method, FormAction, HTTP_VERSION, NULL, (const char**)&accept, 0, 1); if (!hRequest) { return 2; } // 發送請求 BOOL bSendRequest = HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata)); if (!bSendRequest) { return 2; } ////////////////////////調試用///////////////// #ifdef _DEBUG int bDoLoop = 1; LPTSTR szReadBuffer; DWORD lNumberOfBytesRead; FILE* f1; szReadBuffer = (LPTSTR) malloc(500); ZeroMemory(szReadBuffer, 500); if ((f1=fopen("c:\\test.htm", "w"))!=NULL) { while(bDoLoop) { bDoLoop = InternetReadFile(hRequest, szReadBuffer, 500, &lNumberOfBytesRead); fseek(f1, 0L, SEEK_END); fwrite(szReadBuffer, sizeof(szReadBuffer), lNumberOfBytesRead, f1); if (lNumberOfBytesRead<500) bDoLoop = 0; } } fclose(f1); free(szReadBuffer); #endif ////////////////////////////////////////////////// // 清除句柄 if (hRequest) InternetCloseHandle(hRequest); if (hConnect) InternetCloseHandle(hConnect); if (hSession) InternetCloseHandle(hSession); return 0; } /***************************************************************** * 函數介紹: 發送短信函數 * 輸入參數: char* lpGateway - 發送網關名稱 char* lpUserName - 發送者登陸賬號 char* lpPassword - 發送者登陸密碼 char* lpPhone - 接收者手機號碼 char* lpContent - 發送內容 char* lpNickName - 發送者昵稱 char* lpExtent - 擴展信息 * 輸出參數: 無 * 返 回 值: int 00 - 操作完成,結果未知 01 - 網關代號不存在 02 - 網絡連接超時 03 - 用戶中止操作 04 - 網關/賬號/手機/短信內容空白或非法 05 - 出現其他錯誤 *****************************************************************/ SENDSMS_API int CALLAGREEMENT SendSMS(char* lpGateway, char* lpUserName, char* lpPassword, char* lpPhone, char* lpContent, char* lpNickName, char* lpExtent ) { int Result; static TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded"); static TCHAR accept[] = _T("Accept: */*"); static TCHAR frmdata[1024]; // 登陸姓名,密碼等不允許為空 if ((strlen(lpGateway)<=0)||(strlen(lpUserName)<=0)|| (strlen(lpPassword)<=0)||(strlen(lpPhone)<=0)||(strlen(lpContent)<=0)) return 4; // 選擇網易網關發送 if (strcmp(lpGateway, "163.com")==0) { // 登錄短信發送系統 sprintf(frmdata, "username=%s&password=%s", lpUserName, lpPassword); Result = doHTTP(hdrs, accept, "POST", frmdata, "reg4.163.com", "/in.jsp"); // 發送短信 if (strlen(lpNickName)>0) sprintf(frmdata, "send=1&phone=%s&message=%s--%s", lpPhone, lpContent, lpNickName); else sprintf(frmdata, "send=1&phone=%s&message=%s", lpPhone, lpContent); Result = doHTTP(hdrs, accept, "POST", frmdata, "sms.163.com", "/service/sendmsg_pop.php"); // 退出短信發送系統 sprintf(frmdata, "username=%s", lpUserName); Result = doHTTP(hdrs, accept, "GET", frmdata, "reg4.163.com", "/Logout.jsp"); return Result; } // 選擇搜狐網關發送 if (strcmp(lpGateway, "sohu.com")==0) { Result = 1; return Result; } // 網關代號不存在 return 1; } 以上是一個利用網頁發送短信息的函數,里面有你想要的功能。。 |
wu_chang(無常來去) 於 2004-7-6 11:57:06 | 事實上大家的方法都是對的,但是關鍵在於FORM提交的時候,遇到非數字或字符,FORM會進行字符轉換,轉換成十六進制的轉義字符,所以我提交的時候總是出錯。所以模擬提交FORM時,要對發送的數據進行一次字符轉換,然后提交。 |