HTTP 301,302 跳轉

  當返回數據含有跳轉地址時,取出Location: 地址,並通過AfxParseURL解析出服務器地址。


  pHttpFile->QueryInfoStatusCode(dwStatusCode);  
  if (dwStatusCode > 300 && dwStatusCode <= 306) {
   CString strNewLocation;
   pHttpFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
   int nPlace = strNewLocation.Find(_T("Location: "));
   if (nPlace == -1)
   {
    goto exit;
   }
   strNewLocation = strNewLocation.Mid(nPlace + 10);
   nPlace = strNewLocation.Find('\n');
   if (nPlace > 0)
   {
    strNewLocation = strNewLocation.Left(nPlace);
   }
   DWORD  dwServiceType;
   CString  strServer;
   CString  strObject;
   INTERNET_PORT nPort;
   AfxParseURL(strNewLocation, dwServiceType, strServer, strObject, nPort);
   strRev = strServer;
   goto exit;
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章