Home > Software engineering >  HTTP upload pictures fail?
HTTP upload pictures fail?

Time:10-06

Below is a HTTP upload online functions:
 UploadFile (LPCTSTR strURL,//receive the upload the URL of the page 
LPCTSTR strLocalFileName)//to upload local file path
{
ASSERT (strURL!=NULL & amp; & StrLocalFileName!=NULL);


BOOL bResult=FALSE;
DWORD dwType=0;
Cstrings strServer.
Cstrings strObject;
INTERNET_PORT wPort=0;
DWORD dwFileLength=0;
Char * pFileBuff=NULL;


CHttpConnection * pHC=NULL;
CHttpFile * pHF=NULL;
CInternetSession cis;


BResult=AfxParseURL (strURL, dwType strServer, strObject, wPort);
if(! BResult)
return FALSE;
CFile file;
Try
{
if(! File. The Open (strLocalFileName, CFile: : shareDenyNone | CFile: : modeRead))
return FALSE;
DwFileLength=file. GetLength ();
If (dwFileLength & lt;=0)
return FALSE;
PFileBuff=new char [dwFileLength];
Memset (pFileBuff, 0, sizeof (char) * dwFileLength);
File. Read (pFileBuff dwFileLength);


Const int nTimeOut=5000;
Cis. SetOption (INTERNET_OPTION_CONNECT_TIMEOUT nTimeOut);//connection timeout
Cis. SetOption (INTERNET_OPTION_CONNECT_RETRIES, 1);//try again 1
PHC=cis. GetHttpConnection (strServer wPort);//get a Http connection


PHF=pHC - & gt; OpenRequest (CHttpConnection: : HTTP_VERB_POST, strObject);
if(! PHF - & gt; The SendRequest (), NULL, 0, pFileBuff dwFileLength)
{
The delete [] pFileBuff;
PFileBuff=NULL;
PHF - & gt; Close ();
PHC - & gt; Close ();
Cis. The Close ();
return FALSE;
}
DWORD dwStateCode=0;
PHF - & gt; QueryInfoStatusCode (dwStateCode);


If (dwStateCode==HTTP_STATUS_OK)
BResult=TRUE;
}


The catch (CInternetException * pEx)
{
Char sz [256]="";
PEx - & gt; GetErrorMessage (sz, 25);
Cstrings STR.
STR. The Format (" InternetException occur! The \ r \ n % s ", sz);
AfxMessageBox(str);
}
The catch (CFileException& Fe)
{
Cstrings STR.
STR. The Format (" FileException occur! \ r \ n % d ", fe m_lOsError);
AfxMessageBox(str);
}
The catch ()
{
DWORD dwError=GetLastError ();
Cstrings STR.
STR. The Format (" Unknow Exception occur! The \ r \ n % d ", dwError);
AfxMessageBox(str);
}


The delete [] pFileBuff;
PFileBuff=NULL;
File. The Close ();
PHF - & gt; Close ();
PHC - & gt; Close ();
Cis. The Close ();
Return bResult;
}

Then I will D plate image upload, found that the function returns is true, but no things on the Web server,
Here is my call:
UploadFile (" http://192.168.15.30:8090/user ", "D://ihs. BMP")
Then use the
UploadFile (" http://192.168.15.30:8090 ", "D://ihs. BMP")
Still the same failure!

CodePudding user response:

How to write the server receives the picture code?
  • Related