搜索

首页  >  问答  >  正文

c++ 编写httpget下载七牛资源报错 报错位置如下!谢谢你们帮我解答!

UINT CHTTPDownload::SendRequest(BOOL bHead)
{

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

<code>CString strVerb;

if( bHead )    strVerb = _T("HEAD ");

else           strVerb = _T("GET ");

 

CString            strSend,strHeader,strRange;

 

int                iStatus = 0, nRet;

char            szReadBuf[1025];

DWORD            dwContentLength,dwStatusCode;

 

while (TRUE)

{

    if(m_pSocket.m_hSocket != NULL)

        m_pSocket.Close();

    m_pSocket.Create();

    m_pSocket.Connect(m_strServer, m_nPort);

     

    strSend  = strVerb  + m_strObject + " HTTP/1.1\r\n";

    strSend += "Host: " + m_strServer + "\r\n";

    strSend += "Accept: */*\r\n";

    strSend += "Pragma: no-cache\r\n";

    strSend += "Cache-Control: no-cache\r\n";

    if( !m_strReferer.IsEmpty() )

        strSend += "Referer: " + m_strReferer + "\r\n";

    strSend += "Connection: close\r\n";

    strRange = "Range: bytes=100-\r\n";

    strSend += strRange;       

    strSend += "\r\n";//必须要加一个空行,否则Http服务器将不会应答

     

    int ret = m_pSocket.Send(strSend.GetBuffer(0), strSend.GetLength());

    strSend.ReleaseBuffer();

     

    strHeader.Empty();

    while( TRUE )

    {

        ZeroMemory(szReadBuf,1025);

        ret = m_pSocket.Receive(szReadBuf, 1025);

         

        if( szReadBuf[0] == '\0' ) // We have encountered "\r\n\r\n"

            break;

         

        strHeader += szReadBuf;

        if( iStatus == 0)

            strHeader += "\r\n";

    }

     

    nRet = GetInfo(strHeader,dwContentLength,dwStatusCode,m_TimeLastModified);

    switch ( nRet )

    {

        case HTTP_FAIL:

            return SENDREQUEST_FAIL;

            break;

        case HTTP_ERROR:

            return SENDREQUEST_ERROR;

            break;

        case HTTP_REDIRECT:

            continue;

            break;

        case HTTP_OK:

            m_dwDownloadSize = dwContentLength + 100;

         

        if( strRange.IsEmpty() )

            m_dwFileSize = dwContentLength + 100; // 整个文件的长度

        else

        {

            if ( dwStatusCode == 206 )    //支持断点续传

            {

                m_bSupportResume = TRUE;

                m_dwFileSize = dwContentLength + 100;

            }

            else                        //不支持断点续传

            {

                m_bSupportResume = FALSE;

                m_dwFileSize = dwContentLength + 100;

            }

        }

        return SENDREQUEST_SUCCESS;

        break;

    default:

        return SENDREQUEST_FAIL;

        break;

    }

}

m_pSocket.Close();

return SENDREQUEST_SUCCESS;</code>

}

迷茫迷茫2811 天前514

全部回复(0)我来回复

暂无回复
  • 取消回复