Following code unable to write/upload file on a HTTP Server
-
My following code is unable to upload/write file on the server. Please tell me whats wrong or how can i upload it in a different way on an HTTP Server. I am using MFC.
INTERNET_BUFFERS BufferIn = {0};
DWORD dwBytesRead;
DWORD dwBytesWritten;
BYTE pBuffer[1024]; // Read from file in 1K chunks
BOOL bRead, bRet;
HANDLE hFile;HINTERNET hSession = InternetOpen(NULL, INTERNET\_OPEN\_TYPE\_PRECONFIG, NULL, NULL, 0); HINTERNET hConnection = InternetConnect(hSession, \_T("www.crmpanel.com"), // Server INTERNET\_DEFAULT\_HTTP\_PORT, NULL, // Username NULL, // Password INTERNET\_SERVICE\_HTTP, 0, // Synchronous NULL); // No Context BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS ); HINTERNET hRequest = HttpOpenRequest(hConnection, \_T("PUT"), \_T("cp3/wn\_fupload-oo.php"), NULL, NULL, NULL, 0, 0); if (!hRequest) { //printf("Failed to open request handle: %lu\\n", GetLastError ()); MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK); return ; } //HttpAddRequestHeaders(hRequest, \_T("Content-Type: multipart/form-data;sid=52501;"), -1, HTTP\_ADDREQ\_FLAG\_ADD); hFile = CreateFile (\_T("c:\\\\Image1.gif"), GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE\_NORMAL, NULL); if (hFile == INVALID\_HANDLE\_VALUE) { //printf("\\nFailed to open local file."); MessageBox(\_T("Failed to open local file"),NULL,MB\_OK); return ; } BufferIn.dwBufferTotal = GetFileSize(hFile, NULL); MessageBox(\_T("File size is"),NULL,MB\_OK); //printf ("File size is %d\\n");//, BufferIn.dwBufferTotal ); // CString h = \_T("Content-Type: multipart/form-data"); //CString s = \_T("filename=Iamge1.xml&filetype=gif&filesize=70204&sid=52501&csesid=111"); //BOOL bo = HttpSendRequest(hRequest,(LPCTSTR)&h, h.GetLength(),(LPVOID)&s ,s.GetLength());
-
My following code is unable to upload/write file on the server. Please tell me whats wrong or how can i upload it in a different way on an HTTP Server. I am using MFC.
INTERNET_BUFFERS BufferIn = {0};
DWORD dwBytesRead;
DWORD dwBytesWritten;
BYTE pBuffer[1024]; // Read from file in 1K chunks
BOOL bRead, bRet;
HANDLE hFile;HINTERNET hSession = InternetOpen(NULL, INTERNET\_OPEN\_TYPE\_PRECONFIG, NULL, NULL, 0); HINTERNET hConnection = InternetConnect(hSession, \_T("www.crmpanel.com"), // Server INTERNET\_DEFAULT\_HTTP\_PORT, NULL, // Username NULL, // Password INTERNET\_SERVICE\_HTTP, 0, // Synchronous NULL); // No Context BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS ); HINTERNET hRequest = HttpOpenRequest(hConnection, \_T("PUT"), \_T("cp3/wn\_fupload-oo.php"), NULL, NULL, NULL, 0, 0); if (!hRequest) { //printf("Failed to open request handle: %lu\\n", GetLastError ()); MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK); return ; } //HttpAddRequestHeaders(hRequest, \_T("Content-Type: multipart/form-data;sid=52501;"), -1, HTTP\_ADDREQ\_FLAG\_ADD); hFile = CreateFile (\_T("c:\\\\Image1.gif"), GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE\_NORMAL, NULL); if (hFile == INVALID\_HANDLE\_VALUE) { //printf("\\nFailed to open local file."); MessageBox(\_T("Failed to open local file"),NULL,MB\_OK); return ; } BufferIn.dwBufferTotal = GetFileSize(hFile, NULL); MessageBox(\_T("File size is"),NULL,MB\_OK); //printf ("File size is %d\\n");//, BufferIn.dwBufferTotal ); // CString h = \_T("Content-Type: multipart/form-data"); //CString s = \_T("filename=Iamge1.xml&filetype=gif&filesize=70204&sid=52501&csesid=111"); //BOOL bo = HttpSendRequest(hRequest,(LPCTSTR)&h, h.GetLength(),(LPVOID)&s ,s.GetLength());
Dhiraj kumar Saini wrote:
My following code is unable to upload/write file on the server.
And? How are we supposed to offer any suggestions if you don't tell us what is wrong, what you've tried, etc?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch