//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS / // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" / #undef APSTUDIO_READONLY_SYMBOLS / // Chinese (P.R.C.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) #ifdef _WIN32 LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED #pragma code_page(936) #endif //_WIN32 #ifdef APSTUDIO_INVOKED / // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h/0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""/r/n" "/0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "#define _AFX_NO_SPLITTER_RESOURCES/r/n" "#define _AFX_NO_OLE_RESOURCES/r/n" "#define _AFX_NO_TRACKER_RESOURCES/r/n" "#define _AFX_NO_PROPERTY_RESOURCES/r/n" "/r/n" "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)/r/n" "#ifdef _WIN32/r/n" "LANGUAGE 4, 2/r/n" "#pragma code_page(936)/r/n" "#endif //_WIN32/r/n" "#include ""res//HotpimUpload.rc2"" // non-Microsoft Visual C++ edited resources/r/n" "#include ""l.chs//afxres.rc"" // Standard components/r/n" "#endif/r/n" "/0" END #endif // APSTUDIO_INVOKED / // // Icon // // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDR_MAINFRAME ICON DISCARDABLE "res//HotpimUpload.ico" / // // Dialog // IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "关于 HotpimUpload" FONT 9, "宋体" BEGIN ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 LTEXT "HotpimUpload 1.0 版",IDC_STATIC,40,10,119,8,SS_NOPREFIX LTEXT "版权所有 (C) 2007",IDC_STATIC,40,25,119,8 DEFPUSHBUTTON "确定",IDOK,178,7,50,14,WS_GROUP END IDD_HOTPIMUPLOAD_DIALOG DIALOGEX 0, 0, 320, 200 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "HotpimUpload" FONT 9, "宋体" BEGIN DEFPUSHBUTTON "确定",IDOK,260,7,50,14 PUSHBUTTON "取消",IDCANCEL,260,23,50,14 PUSHBUTTON "Upload",IDC_BUTTON1,97,96,50,14 END #ifndef _MAC / // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x4L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "080404B0" BEGIN VALUE "CompanyName", "/0" VALUE "FileDescription", "HotpimUpload Microsoft 基础类应用程序/0" VALUE "FileVersion", "1, 0, 0, 1/0" VALUE "InternalName", "HotpimUpload/0" VALUE "LegalCopyright", "版权所有 (C) 2007/0" VALUE "LegalTrademarks", "/0" VALUE "OriginalFilename", "HotpimUpload.EXE/0" VALUE "ProductName", "HotpimUpload 应用程序/0" VALUE "ProductVersion", "1, 0, 0, 1/0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x804, 1200 END END #endif // !_MAC / // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN IDD_ABOUTBOX, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 228 TOPMARGIN, 7 BOTTOMMARGIN, 48 END IDD_HOTPIMUPLOAD_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 313 TOPMARGIN, 7 BOTTOMMARGIN, 193 END END #endif // APSTUDIO_INVOKED / // // String Table // STRINGTABLE DISCARDABLE BEGIN IDS_ABOUTBOX "关于 HotpimUpload(&A)..." END #endif // Chinese (P.R.C.) resources / #ifndef APSTUDIO_INVOKED / // // Generated from the TEXTINCLUDE 3 resource. // #define _AFX_NO_SPLITTER_RESOURCES #define _AFX_NO_OLE_RESOURCES #define _AFX_NO_TRACKER_RESOURCES #define _AFX_NO_PROPERTY_RESOURCES #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) #ifdef _WIN32 LANGUAGE 4, 2 #pragma code_page(936) #endif //_WIN32 #include "res/HotpimUpload.rc2" // non-Microsoft Visual C++ edited resources #include "l.chs/afxres.rc" // Standard components #endif / #endif // not APSTUDIO_INVOKED
*****************************************************
// HotpimUpload.h : main header file for the HOTPIMUPLOAD application // #if !defined(AFX_HOTPIMUPLOAD_H__A9E6D79F_4DFA_4E7B_A968_2DBAA1646E11__INCLUDED_) #define AFX_HOTPIMUPLOAD_H__A9E6D79F_4DFA_4E7B_A968_2DBAA1646E11__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols / // CHotpimUploadApp: // See HotpimUpload.cpp for the implementation of this class // class CHotpimUploadApp : public CWinApp { public: CHotpimUploadApp(); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CHotpimUploadApp) public: virtual BOOL InitInstance(); //}}AFX_VIRTUAL // Implementation //{{AFX_MSG(CHotpimUploadApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP() }; / //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_HOTPIMUPLOAD_H__A9E6D79F_4DFA_4E7B_A968_2DBAA1646E11__INCLUDED_)
// HotpimUpload.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "HotpimUpload.h" #include "HotpimUploadDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CHotpimUploadApp BEGIN_MESSAGE_MAP(CHotpimUploadApp, CWinApp) //{{AFX_MSG_MAP(CHotpimUploadApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() / // CHotpimUploadApp construction CHotpimUploadApp::CHotpimUploadApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } / // The one and only CHotpimUploadApp object CHotpimUploadApp theApp; / // CHotpimUploadApp initialization BOOL CHotpimUploadApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CHotpimUploadDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
// HotpimUploadDlg.h : header file // #include "afxwin.h" #include "afxinet.h" #if !defined(AFX_HOTPIMUPLOADDLG_H__23002D4A_FF06_4C6F_87AE_EF784060B8A2__INCLUDED_) #define AFX_HOTPIMUPLOADDLG_H__23002D4A_FF06_4C6F_87AE_EF784060B8A2__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 / // CHotpimUploadDlg dialog class CHotpimUploadDlg : public CDialog { // Construction public: CHttpConnection* m_pConnection; CString MakeRequestHeaders(CString& strBoundary); CString MakePreFileData(CString& strBoundary, CString& strFileName, int iRecordID); CString MakePostFileData(CString& strBoundary); BOOL SendTrack(); CHotpimUploadDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CHotpimUploadDlg) enum { IDD = IDD_HOTPIMUPLOAD_DIALOG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CHotpimUploadDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CHotpimUploadDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnButton1(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_HOTPIMUPLOADDLG_H__23002D4A_FF06_4C6F_87AE_EF784060B8A2__INCLUDED_)
// HotpimUploadDlg.cpp : implementation file // #include "stdafx.h" #include "HotpimUpload.h" #include "HotpimUploadDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CHotpimUploadDlg dialog CHotpimUploadDlg::CHotpimUploadDlg(CWnd* pParent /*=NULL*/) : CDialog(CHotpimUploadDlg::IDD, pParent) { //{{AFX_DATA_INIT(CHotpimUploadDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CHotpimUploadDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CHotpimUploadDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CHotpimUploadDlg, CDialog) //{{AFX_MSG_MAP(CHotpimUploadDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CHotpimUploadDlg message handlers BOOL CHotpimUploadDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CHotpimUploadDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CHotpimUploadDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CHotpimUploadDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CHotpimUploadDlg::OnButton1() { // TODO: Add your control notification handler code here SendTrack();//发送数据 } CString CHotpimUploadDlg::MakeRequestHeaders(CString &strBoundary)//包头 { CString strFormat; CString strData; strFormat = _T("Content-Type: multipart/form-data; boundary=%s/r/n");//二进制文件传送Content-Type类型为: multipart/form-data strData.Format(strFormat, strBoundary); return strData; } CString CHotpimUploadDlg::MakePreFileData(CString &strBoundary, CString &strFileName, int iRecordID) { /**/ //Content-Type: //JPG image/pjpeg //PNG image/x-png //BMP image/bmp //TIF image/tiff //GIF image/gif CString strFormat; CString strData; strFormat += _T("--%s"); strFormat += _T("/r/n"); strFormat += _T("Content-Disposition: form-data; name=/"para1/"");//传给网络上的参数,根据网站抓包查看到底是需要哪些 strFormat += _T("/r/n/r/n"); strFormat += _T("my name is xiaoxiong"); strFormat += _T("/r/n"); strFormat += _T("--%s"); strFormat += _T("/r/n"); strFormat += _T("Content-Disposition: form-data; name=/"para2/""); strFormat += _T("/r/n/r/n"); strFormat += _T("国软软件研究所"); strFormat += _T("/r/n"); strFormat += _T("--%s"); strFormat += _T("/r/n"); strFormat += _T("Content-Disposition: form-data; name=/"trackdata/"; filename=/"%s/"");//文件地址信息 strFormat += _T("/r/n"); strFormat += _T("Content-Type: image/pjpeg"); strFormat += _T("/r/n/r/n"); strData.Format(strFormat, strBoundary, strBoundary, strBoundary, strFileName);// return strData; } CString CHotpimUploadDlg::MakePostFileData(CString &strBoundary)//发送请求包 { CString strFormat; CString strData; strFormat = _T("/r/n"); strFormat += _T("--%s"); strFormat += _T("/r/n"); strFormat += _T("Content-Disposition: form-data; name=/"submitted/""); strFormat += _T("/r/n/r/n"); strFormat += _T("hello"); strFormat += _T("/r/n"); strFormat += _T("--%s--"); strFormat += _T("/r/n"); strData.Format(strFormat, strBoundary, strBoundary); return strData; } BOOL CHotpimUploadDlg::SendTrack()//发送数据 { CString _mFilePath; _mFilePath = "C://GuoRuan//pagefile.jpg";//要传的本地文件地址 int startp = _mFilePath.ReverseFind('//'); int namelen = _mFilePath.GetLength()-startp-1; CString pcmname = _mFilePath;//.Mid(startp+1,namelen); //由于是公司那边的服务器,我不能把地址按公司的给你们,你们自已找个图片上传PC端软件,然后抓包,进行发送 //www.GuoRuan.com这个网址是一个可以用PC端软件进行网站的文件传输,可以用抓包工具抓包查看它那边网站所要的信息对程序相应的修改 //本程序已在我所在的公司测试OK CString defServerName ="www.GuoRuan.com";//服务器名 CString defObjectName ="/system/UploadScreen/upfile_article.asp";//保存的地址 // USES_CONVERSION; CInternetSession Session; CHttpConnection *pHttpConnection = NULL; INTERNET_PORT nPort = 80; CFile fTrack; CHttpFile* pHTTP; CString strHTTPBoundary; CString strPreFileData; CString strPostFileData; DWORD dwTotalRequestLength; DWORD dwChunkLength; DWORD dwReadLength; DWORD dwResponseLength; TCHAR szError[MAX_PATH]; void* pBuffer; LPSTR szResponse; CString strResponse; BOOL bSuccess = TRUE; CString strDebugMessage; if (FALSE == fTrack.Open(_mFilePath, CFile::modeRead | CFile::shareDenyWrite))//读出文件 { AfxMessageBox(_T("Unable to open the file.")); return FALSE; } int iRecordID = 1; strHTTPBoundary = _T("---------------------------7b4a6d158c9");//定义边界值 strPreFileData = MakePreFileData(strHTTPBoundary, pcmname, iRecordID); strPostFileData = MakePostFileData(strHTTPBoundary); dwTotalRequestLength = strPreFileData.GetLength() + strPostFileData.GetLength() + fTrack.GetLength();//计算整个包的总长度 dwChunkLength = 64 * 1024; pBuffer = malloc(dwChunkLength); if (NULL == pBuffer) { return FALSE; } try { pHttpConnection = Session.GetHttpConnection(defServerName,nPort); pHTTP = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, defObjectName); pHTTP->AddRequestHeaders(MakeRequestHeaders(strHTTPBoundary));//发送包头请求 pHTTP->SendRequestEx(dwTotalRequestLength, HSR_SYNC | HSR_INITIATE); #ifdef _UNICODE pHTTP->Write(W2A(strPreFileData), strPreFileData.GetLength()); #else pHTTP->Write((LPSTR)(LPCSTR)strPreFileData, strPreFileData.GetLength());//写入服务器所需信息 #endif dwReadLength = -1; while (0 != dwReadLength) { strDebugMessage.Format(_T("%u / %u/n"), fTrack.GetPosition(), fTrack.GetLength()); TRACE(strDebugMessage); dwReadLength = fTrack.Read(pBuffer, dwChunkLength);//文件内容 if (0 != dwReadLength) { pHTTP->Write(pBuffer, dwReadLength);//写入服务器本地文件,用二进制进行传送 } } #ifdef _UNICODE pHTTP->Write(W2A(strPostFileData), strPostFileData.GetLength()); #else pHTTP->Write((LPSTR)(LPCSTR)strPostFileData, strPostFileData.GetLength()); #endif pHTTP->EndRequest(HSR_SYNC); dwResponseLength = pHTTP->GetLength(); while (0 != dwResponseLength) { szResponse = (LPSTR)malloc(dwResponseLength + 1); szResponse[dwResponseLength] = '/0'; pHTTP->Read(szResponse, dwResponseLength); strResponse += szResponse; free(szResponse); dwResponseLength = pHTTP->GetLength(); } } catch (CException* e) { e->GetErrorMessage(szError, MAX_PATH); e->Delete(); AfxMessageBox(szError); bSuccess = FALSE; } pHTTP->Close(); delete pHTTP; fTrack.Close(); if (NULL != pBuffer) { free(pBuffer); } return bSuccess; }