首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC http上传图片,不是很明白,帮忙指点下解决方案

2014-05-12 
VC http上传图片,不是很明白,帮忙指点下html页面请求:成功,在页面上浏览一张图片,上传可以成功

VC http上传图片,不是很明白,帮忙指点下
html页面请求:成功,在页面上浏览一张图片,上传可以成功
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form action="http://127.0.0.1/index.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
  
  <input name="AC" type="text" id="AC" value="SendImg" /> 
  <input name="UserID" type="text" id="UserID" value="140606" /> 
  <input name="Key" type="text" id="Key" value="xxx" />
<input name="ImgID" type="text" id="ImgID" value="140606" />
  <input name="GroupID" type="text" id="GroupID" value="102" /> 
  <input name="IMG" type="file" id="IMG" /> 
  <input type="submit" name="Submit" value="提交" /> 
</form>
</body>
</html>

在VC里应该怎么post图片数据呢???


[解决办法]
这不是php吗
[解决办法]
用工具截包看看就知道啦,比如httpwatch
[解决办法]

C/C++ code
BOOL UseHttpSendReqEx(TCHAR *upFile){HINTERNET hSession=NULL, hConnect=NULL, hRequest=NULL;hSession = InternetOpen(_T("test"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);hConnect = InternetConnect(hSession,_T("192.168.0.100"), INTERNET_DEFAULT_HTTP_PORT,  NULL,NULL,INTERNET_SERVICE_HTTP,INTERNET_FLAG_NO_CACHE_WRITE,NULL);  INTERNET_BUFFERS BufferIn = {0};  DWORD dwBytesRead;  DWORD dwBytesWritten;  BYTE pBuffer[1024]; // Read from file in 1K chunks  BOOL bRead, bRet;  BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );  hRequest = HttpOpenRequest (hConnect, "POST",  "/mydirectory/test.txt", NULL, NULL, NULL, 0, 0);  if (!hRequest)  {  printf("Failed to open request handle: %lu\n", GetLastError ());  return FALSE;  }  HANDLE hFile = CreateFile (upFile, GENERIC_READ, FILE_SHARE_READ,  NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);  if (hFile == INVALID_HANDLE_VALUE)  {  printf("\nFailed to open local file %s.", upFile);  return FALSE;  }  BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);  printf ("File size is %d\n", BufferIn.dwBufferTotal );  if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE, 0))  {  printf( "Error on HttpSendRequestEx %lu\n",GetLastError() );  return FALSE;  }  DWORD sum = 0;  do  {  if (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),  &dwBytesRead, NULL)))  {  printf ("\nReadFile failed on buffer %lu.",GetLastError());  break;  }  if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,  &dwBytesWritten)))  {  printf ("\nInternetWriteFile failed %lu", GetLastError());  break;  }  sum += dwBytesWritten;  }  while (dwBytesRead == sizeof(pBuffer)) ;  CloseHandle (hFile);  printf ("Actual written bytes: %d\n", sum);  if(!HttpEndRequest(hRequest, NULL, 0, 0))  {  printf( "Error on HttpEndRequest %lu \n", GetLastError());  return FALSE;  }  return TRUE;}
------解决方案--------------------


用抓包工具抓个包看看发送了哪些数据,然后利用WinINET的CInternetSession类相关的发送出去就可以了

热点排行