Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 14-04-2009
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.210
Poder: 22
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Hola de nuevo, yelian.

Si tu programa parece "colgado" durante la descarga, quizás deberías pensar en colocar tu código de descarga en un hilo a parte. Otra posibilidad sería establecer un IBindStatusCallback y colocar Application->ProcessMessages(); en el evento OnProgress.

Para el problema del proxy, debes realizar una autentificación previa a la descarga. Te dejo un ejemplo:
Código:
//---------------------------------------------------------------------------
bool Authenticate(HWND hWnd, char *URL)
{
   HINTERNET hOpenHandle,  hConnectHandle, hResourceHandle;
   DWORD dwError, dwErrorCode;
   char c;
   URL_COMPONENTS URL_C = {sizeof(URL_COMPONENTS)};
   URL_C.lpszScheme = &c;
   URL_C.dwSchemeLength = 1;
   URL_C.lpszHostName = &c;
//   URL_C.dwHostNameLength = 0;
   URL_C.lpszUserName  = &c;
//   URL_C.dwUserNameLength = 0;
   URL_C.lpszPassword = &c;
//   URL_C.dwPasswordLength = 0;
   URL_C.lpszUrlPath = &c;
//   URL_C.dwUrlPathLength = 0;
   URL_C.lpszExtraInfo = &c;
//   URL_C.dwExtraInfoLength = 0;

   InternetCrackUrl(URL, strlen(URL), ICU_DECODE, &URL_C);

   URL_C.lpszScheme = new char[URL_C.dwSchemeLength];
   URL_C.lpszHostName = new char[URL_C.dwHostNameLength];
   URL_C.lpszUserName  = new char[URL_C.dwUserNameLength];
   URL_C.lpszPassword = new char[URL_C.dwPasswordLength];
   URL_C.lpszUrlPath = new char[URL_C.dwUrlPathLength];
   URL_C.lpszExtraInfo = new char[URL_C.dwExtraInfoLength];

   InternetCrackUrl(URL, strlen(URL), ICU_DECODE, &URL_C);

   hOpenHandle = InternetOpen("Agent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

   hConnectHandle = InternetConnect(hOpenHandle,
                                 URL_C.lpszHostName,
                                 INTERNET_INVALID_PORT_NUMBER,
                                 NULL,
                                 NULL,
                                 INTERNET_SERVICE_HTTP,
                                 0,0);

   hResourceHandle = HttpOpenRequest(hConnectHandle, "GET",
                                  URL_C.lpszUrlPath,
                                  NULL, NULL, NULL,
                                  INTERNET_FLAG_KEEP_CONNECTION, 0);

   delete URL_C.lpszScheme;
   delete URL_C.lpszHostName;
   delete URL_C.lpszUserName;
   delete URL_C.lpszPassword;
   delete URL_C.lpszUrlPath;
   delete URL_C.lpszExtraInfo;
   
   for(int n=0; n<2; n++){
      HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0);
      dwErrorCode = hResourceHandle ? ERROR_SUCCESS : GetLastError();
      dwError = InternetErrorDlg(hWnd, hResourceHandle, dwErrorCode,
                           FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
                           FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
                           FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
                           NULL);
      if (dwError != ERROR_INTERNET_FORCE_RETRY)
        break;
   }
   return (dwError != ERROR_INTERNET_FORCE_RETRY);}
Y como usarlo en una descarga:

Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    char File[] = "http://www.terawiki.clubdelphi.com/CPPBuilderWin32/Ejemplos/?download=Otro+Usuario.rar";
    HRESULT R;

    Authenticate(Handle, File);
    R = URLDownloadToFile(0, File, "C:\\File.rar", 0, 0);
}
Saludos.

PD He optimizado un poco el código.

Última edición por escafandra fecha: 15-04-2009 a las 18:50:59. Razón: Optimización de código
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Descargar un archivo de Internet c0lo Internet 10 14-05-2016 04:44:25
como descargar ficheros de internet jfadelphi Varios 3 04-03-2009 09:14:59
Descargar Archivos Deiv HTML, Javascript y otros 6 25-12-2007 08:52:55
Descargar fichero 25 Mb desde internet fmatias Internet 4 06-07-2007 17:43:59
Descargar imágenes de internet via http. alfredosg19 Internet 2 08-04-2005 13:02:27


La franja horaria es GMT +2. Ahora son las 14:15:23.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi