vchttp文件上傳
Ⅰ 如何用VC發送http請求
1、創建socket,利用tcp鏈接伺服器。
2、按照http協議的格式組裝請求字元串。
3、利用socket發送字元串。
Ⅱ ASP如何解析VC利用HTTP POST過i來的數據也就是把圖片文件取出來保存 -
http post 過來的,vc post 和普通頁面直接加個 input type=「file」 的一樣的 ,普通的怎麼保存就怎麼保存
還是可以 request 接收到 file ,直接保存成為一個文件的。
首先你看下你自己 寫一個上傳文件的程序,自己上傳,自己保存能不能搞定,如果能搞定的話,這個vc的我看下那個http 頭是一樣的 ,應該可以直接一樣接受,因為遵循的協議是一樣的!
Ⅲ vc++ 實現http 哪種方案最好
各有特點。以下是兩個文件:HttpClient.h   HttpClient.cpp   一個類   
  (錯誤檢測部分沒有加入)   
  使用方法   
  1:get方式   
 CHttpClient   conn;
  CString   value="http://8crystal.com/test.asp";
                    value=conn.doGet(value);
2:post方式   
CHttpClient   conn;
  CString   value="http://8crystal.com/test.asp";
  conn.addParam("name1","value1");
  conn.addParam("name2","value2");
  conn.addParam("name3","value3");
  conn.addParam("name4","value4");
  conn.addParam("name5","value5");
  conn.addParam("name6","value6");
  value=conn.doPost(value);
  //   HttpClient.h:   interface   for   the   CHttpClient   class.
  //
  //////////////////////////////////////////////////////////////////////
  #if   !defined(AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_)
  #define   AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_
  #if   _MSC_VER   >   1000
  #pragma   once
  #endif   //   _MSC_VER   >   1000
  #include   "wininet.h"
  #include   "afxinet.h"
  class   CHttpClient
  {
  public:
  void   addParam(CString   name,CString   value);
  CString   doPost(CString   href);
  CString   doGet(CString   href);
  CHttpClient();
  virtual   ~CHttpClient();
  private:
  CString   CONTENT;
  int   CL;
  CStringList   values;
  CStringList   names;
  };
  #endif   //   !defined(AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_)
  ++++++++++++++++++++++++++++++++++++++
//   HttpClient.cpp:   implementation   of   the   CHttpClient   class.
  //
  //////////////////////////////////////////////////////////////////////
  #include   "stdafx.h"
  #include   "emailsenderv2.h"
  #include   "HttpClient.h"
  #ifdef   _DEBUG
  #undef   THIS_FILE
  static   char   THIS_FILE[]=__FILE__;
  #define   new   DEBUG_NEW
  #endif
  //////////////////////////////////////////////////////////////////////
  //   Construction/Destruction
  //////////////////////////////////////////////////////////////////////
  CHttpClient::CHttpClient()
  {
  }
  CHttpClient::~CHttpClient()
  {
  }
  CString   CHttpClient::doGet(CString   href)
  {
  CString   httpsource="";
  CInternetSession   session1(NULL,0);
  CHttpFile*   pHTTPFile=NULL;
  try{
  pHTTPFile=(CHttpFile*)session1.OpenURL(href);
  //session1.
  }catch(CInternetException){
  pHTTPFile=NULL;
  }
  if(pHTTPFile)
  {
  CString   text;
  for(int   i=0;pHTTPFile->ReadString(text);i++)
  {
  httpsource=httpsource+text+"rn";
  }
  pHTTPFile->Close();
  delete   pHTTPFile;
  }else
  {
  }
  return   httpsource;
  }
  CString   CHttpClient::doPost(CString   href)
  {
  CString   httpsource="";
  CInternetSession   session1;
  CHttpConnection*   conn1=NULL;
          CHttpFile*   pFile   =   NULL;
  CString   strServerName;
          CString   strObject;
          INTERNET_PORT   nPort;
          DWORD   dwServiceType;
  AfxParseURL((LPCTSTR)href,dwServiceType,   strServerName,   strObject,   nPort);
          DWORD   retcode;
          char*   outBuff   =   CONTENT.GetBuffer(1000);
          try
          {
                  conn1   =   session1.GetHttpConnection(strServerName,nPort);
                  pFile   =   conn1->OpenRequest(0,strObject,NULL,1,NULL,"HTTP/1.1",INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);
                  pFile   ->   AddRequestHeaders("Content-Type:   application/x-www-form-urlencoded");
                  pFile   ->   AddRequestHeaders("Accept:   */*");
                  pFile   ->   SendRequest(NULL,0,outBuff,strlen(outBuff)+1);
                  pFile   ->   QueryInfoStatusCode(retcode);
          }
          catch   (CInternetException   *   e){};
  if(pFile)
  {
  CString   text;
  for(int   i=0;pFile->ReadString(text);i++)
  {
  httpsource=httpsource+text+"rn";
  }
  pFile->Close();
  }else
  {
  }
  return   httpsource;
          delete   pFile;
          delete   conn1;
          session1.Close();
  }
  void   CHttpClient::addParam(CString   name,   CString   value)
  {
  names.AddTail((LPCTSTR)name);
  values.AddTail((LPCTSTR)value);
  CString   eq="=";
  CString   an="&";
  CONTENT=CONTENT+name+eq+value+an;
  CL=CONTENT.GetLength();
  }
Ⅳ 怎麼用VC實現基於HTTP的上傳文件
CHttpFile
CHttpConnection
CInternetSession
MFC中使用這個幾個類來實現HTTP協議的數據傳輸。
具體使用方法看MSDN吧,網上搜索也能搜到例子,我就不貼代碼了。
Ⅳ 區域網 文件傳輸 VC
可靠的話要用TCP ,
實現簡單速度快的話就用UDP.
關鍵是看你傳什麼文件,如果不是非常重要一般都用UDP。
TCP的話實現復雜,而且速度慢。
Ⅵ VC如何實現多線程文件傳輸
發送端,將文件分成N份(如5),FILE1(0-a位元組),FILE2(a-b位元組),FILE3(b-c位元組),FILE4(c-d位元組),FILE5(d-文件長度)。 發送可以使用M個線程(如5),THREAD1負責發送FILE1,依次類推,發送的每個數據包包括如下內容:文件內容的長度,文件內容,文件內容起始點相對於整個文件的位置,文件內容相對於整個文件的位置。例如:文件A的總長度為100000位元組,則可以先發送一個數據包給接收端,讓其准備接收,接著發送 4000(長度),....(內容的二進制流),0(起始),4000(結束)。 接收端根據接收的包寫文件即可。 http://www.vckbase.com/document/viewdoc/?id=448 看一下吧
Ⅶ 怎麼HTTP上傳
如何用http上傳一個文件
VC裡面怎麼用http上傳一個文件呢?下載文件有這樣一個函數
HRESULT URLDownloadToCacheFile(
LPUNKNOWN lpUnkcaller,
LPCSTR szURL,
LPTSTR szFileName,
DWORD dwBufLength,
DWORD dwReserved,
IBindStatusCallback *pBSC
);
可以提供回調,顯示進度,有沒有與這個函數相對應的上傳文件的函數呢?或者還有其他的用起來比較方便的函數呢?不想用socket實現http,那樣太麻煩了,我的工程很小的,如果用socket實現http的話會得不償失的
Ⅷ 用VC++做區域網點對點的文件傳輸,文件傳輸已經實現,但是不知道如何實現文件夾的傳輸 。
發發之前簡單協商一下嘛.告訴接收方我要發的這個文件在目錄結構里是什麼情況.服務方根據協商在相對的位置創建文件.然後發文件的過程一樣.
協商: 客戶端說,我要發文件a,它在.\folder1\folder2.大小是38249
伺服器收到檢查一下覺得可以,於是創建.\folder1\folder2\a.然後說,OK,你發吧.
注意是相對路徑不是絕對路徑.
Ⅸ VC++ 頭文件 HttpResponse.h
用#import引入這個dll就可以自動生成tlh文件了,不過GetAllResponseHeaders這個方法好像msdn的例子有點錯誤,這個方法是不接受參數的,字元串通過返回值返回,試了下可行,lz試試看
#include <windows.h>
#include <stdio.h>
#include <objbase.h>
//#include "httprequest.h"
#import <winhttp.dll>
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
// IID for IWinHttpRequest.
const IID IID_IWinHttpRequest =
{
  0x06f29373,
  0x5c5a,
  0x4b54,
  {0xb0, 0x25, 0x6e, 0xf1, 0xbf, 0x8a, 0xbf, 0x0e}
};
int main(int argc, char* argv[])
{
    // variable for return value
    HRESULT    hr;
    // initialize COM
    hr = CoInitialize( NULL );
    WinHttp::IWinHttpRequest *  pIWinHttpRequest = NULL;
    BSTR            bstrResponse = NULL;
    VARIANT         varFalse;
    VARIANT         varEmpty;
    LONG            lStatus;
    BSTR            bstrStatusText;
    
    CLSID           clsid;
    VariantInit(&varFalse);
    V_VT(&varFalse)   = VT_BOOL;
    V_BOOL(&varFalse) = VARIANT_FALSE;
    VariantInit(&varEmpty);
    V_VT(&varEmpty) = VT_ERROR;
    hr = CLSIDFromProgID(L"WinHttp.WinHttpRequest.5.1", &clsid);
    if (SUCCEEDED(hr))
    {
        hr = CoCreateInstance(clsid, NULL, 
                              CLSCTX_INPROC_SERVER, 
                              IID_IWinHttpRequest, 
                              (void **)&pIWinHttpRequest);
    }
    if (SUCCEEDED(hr))
    {    // Open WinHttpRequest.
        BSTR bstrMethod  = SysAllocString(L"GET");
BSTR bstrUrl = SysAllocString(L" http://microsoft.com");
        hr = pIWinHttpRequest->Open(bstrMethod, bstrUrl, 
                                    varFalse);
        SysFreeString(bstrMethod);
        SysFreeString(bstrUrl);
    }
    if (SUCCEEDED(hr))
    {    // Send Request.
        hr = pIWinHttpRequest->Send(varEmpty);
    }
    if (SUCCEEDED(hr))
    {    // Send Request.
        hr = pIWinHttpRequest->get_Status(&lStatus);
        hr = pIWinHttpRequest->get_StatusText(&bstrStatusText);
    }
    if (SUCCEEDED(hr))
    {    // Get Response text.
        //hr = pIWinHttpRequest->GetAllResponseHeaders(&bstrResponse);
        bstrResponse = pIWinHttpRequest->GetAllResponseHeaders();
    }
    if (SUCCEEDED(hr))
    {    // Print response to console.
        wprintf(L"%s\n\n", bstrResponse);
        wprintf(L"%u - %s\n\n", lStatus, bstrStatusText);
    }
    // Release memory.
    if (pIWinHttpRequest)
        pIWinHttpRequest->Release();
    if (bstrStatusText)
        SysFreeString(bstrStatusText);
    if (bstrResponse)
        SysFreeString(bstrResponse);
    
    CoUninitialize();
    return 0;
}
