Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - HTTPwebrequest
Forum - C# / VB.NET - HTTPwebrequest - Pagina 2

Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 15:57
Giovedì, 09/07/2009
Può darsi che non dipenda da tuoi errori! xD prova ad usare la mia classe Download:
Codice sorgente - presumibilmente VB.NET

  1. Class Download
  2. #Region "Events"
  3.     Public Event DownloadStarted As EventHandler
  4.     Public Event DownloadCompleted As EventHandler
  5.     Public Event DownloadProgressChanged As EventHandler
  6.     Public Event DownloadAborted As EventHandler
  7.     Public Event DownloadPaused As EventHandler
  8.     Public Event DownloadResumed As EventHandler
  9. #End Region
  10. #Region "Attributes"
  11.     Private s, d As String
  12.     Private b, sec, v As Decimal
  13.     Dim t As Threading.Thread, ss As IO.BufferedStream, ds As IO.FileStream, dst As DownStatus
  14.     Dim WithEvents tim As New Timer With {.Interval = 1000}
  15. #End Region
  16. #Region "Enums"
  17.     Enum DownStatus
  18.         NoOperation = 0
  19.         Downloading
  20.         Paused
  21.         Completed
  22.     End Enum
  23. #End Region
  24. #Region "Constructors"
  25.     Public Sub New(ByVal url As String, ByVal filename As String)
  26.         s = url
  27.         d = filename
  28.         b = 0
  29.         sec = 0
  30.         t = Nothing
  31.         ss = Nothing
  32.         ds = Nothing
  33.         dst = DownStatus.NoOperation
  34.     End Sub
  35. #End Region
  36. #Region "Properties"
  37.     Public Property Source() As String
  38.         Get
  39.             Return s
  40.         End Get
  41.         Set(ByVal value As String)
  42.             s = value
  43.         End Set
  44.     End Property
  45.     Public Property Destination() As String
  46.         Get
  47.             Return d
  48.         End Get
  49.         Set(ByVal value As String)
  50.             d = value
  51.         End Set
  52.     End Property
  53.     Public ReadOnly Property DownloadedBytes() As Decimal
  54.         Get
  55.             Return b
  56.         End Get
  57.     End Property
  58.     Public ReadOnly Property Seconds() As Decimal
  59.         Get
  60.             Return sec
  61.         End Get
  62.     End Property
  63.     Public ReadOnly Property Speed() As Decimal
  64.         Get
  65.             Return v
  66.         End Get
  67.     End Property
  68.     Public ReadOnly Property DownloadStatus() As DownStatus
  69.         Get
  70.             Return dst
  71.         End Get
  72.     End Property
  73. #End Region
  74. #Region "Public methods"
  75.     Public Sub StartDownload()
  76.         t = New Threading.Thread(AddressOf Download)
  77.         ss = New IO.BufferedStream(Net.WebRequest.Create(s).GetResponse.GetResponseStream)
  78.         ds = New IO.FileStream(d, IO.FileMode.OpenOrCreate)
  79.         tim.Start()
  80.         t.Start()
  81.         dst = DownStatus.Downloading
  82.         RaiseEvent DownloadStarted(Me, New EventArgs)
  83.     End Sub
  84.     Public Sub AbortDownload()
  85.         dst = DownStatus.NoOperation
  86.         t.Abort()
  87.         tim.Stop()
  88.         ds.Close()
  89.         ss.Close()
  90.         RaiseEvent DownloadAborted(Me, New EventArgs)
  91.     End Sub
  92.     Public Sub PauseDownload()
  93.         dst = DownStatus.Paused
  94.         t.Suspend()
  95.         tim.Stop()
  96.         RaiseEvent DownloadPaused(Me, New EventArgs)
  97.     End Sub
  98.     Public Sub ResumeDownload()
  99.         tim.Start()
  100.         t.Resume()
  101.         dst = DownStatus.Downloading
  102.         RaiseEvent DownloadResumed(Me, New EventArgs)
  103.     End Sub
  104. #End Region
  105. #Region "Private methods"
  106.     Private Sub Download()
  107.         While True
  108.             Try
  109.                 ds.WriteByte(ss.ReadByte)
  110.             Catch
  111.                 Exit While
  112.             End Try
  113.             b += 1
  114.             Application.DoEvents()
  115.             RaiseEvent DownloadProgressChanged(Me, New EventArgs)
  116.         End While
  117.         tim.Stop()
  118.         ds.Close()
  119.         ss.Close()
  120.         dst = DownStatus.Completed
  121.         RaiseEvent DownloadCompleted(Me, New EventArgs)
  122.     End Sub
  123. #End Region
  124. #Region "Private events"
  125.     Private Sub tim_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tim.Tick
  126.         sec += 1
  127.         v = b / sec
  128.     End Sub
  129. #End Region
  130. End Class


Dimmi che velocità riesci a raggiungere :D

PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 16:10
Giovedì, 09/07/2009
57 kb/s lmao.... ma che cacchio.....

PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 16:14
Giovedì, 09/07/2009
vogliamo scriverlo usando un socket puro?

PM Quote
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 16:37
Giovedì, 09/07/2009
Azz che lento! xD però...come intendi procedere con i Socket? Io non ho mai provato a scaricare file con un Socket e non so nemmeno a che metodi di connessione si può fare riferimento in questo caso :-?

PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 16:48
Giovedì, 09/07/2009
il problema è che non lo so nemmeno io.... ma se lo hanno fatto i creatori dei download manager possiamo farlo anche noi non credi.....

PM Quote
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 16:52
Giovedì, 09/07/2009
Beh certo xD ho provato a cercare qualcosa, però ora mi sono ricordato che forse con i comandi che utilizza Telnet si può anche scaricare!

Ho appena provato a connettermi al Server e scaricare il file "Colossus.zip":
Codice sorgente - presumibilmente C# / VB.NET

  1. Dim s As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
  2.         s.Connect("colossus.altervista.org", 80)
  3.         s.Send(System.Text.Encoding.ASCII.GetBytes("get /file/Colossus.zip" & Environment.NewLine))


Ma la risposta del Server è questa:
Codice sorgente - presumibilmente Delphi

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  2. <html><head>
  3. <title>501 Method Not Implemented</title>
  4. </head><body>
  5. <h1>Method Not Implemented</h1>
  6. <p>get to /file/Colossus.zip not supported.<br />
  7. </p>
  8. </body></html>


Qualcuno sa spiegarmi il motivo?

Ultima modifica effettuata da riseofapocalypse il 09/07/2009 alle 17:56
PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 19:03
Giovedì, 09/07/2009
è come se quella funzione fosse disabilitata.... volendo... visto che forse è colpa di altervista se è disabilitata... dovrei provare con un server dedicato dove setto io l'apache... e vedere se riesco ad abilitare quella funzione... pero' dove proviamo? mo vedo se riesco a parlare con qualcuno... il problema è che rejetto (HFS) su linux nn ce... va usato per forza apache uff.... forse ci vuole un altro comando al posto del get... nessuno su questo forum sa qualcosa?

http://forum.html.it/forum/showthread/t-1190416.html

vedi se ci puo servire....

Ultima modifica effettuata da GoLDBeRG il 09/07/2009 alle 19:06
PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 19:43
Giovedì, 09/07/2009
Codice sorgente - presumibilmente VB.NET

  1. Imports System
  2. Imports System.IO
  3. Imports System.Net
  4. Imports System.Net.Sockets
  5. Imports System.Threading
  6. Imports System.Text
  7.  
  8. Public Class download
  9.  
  10.     Dim quanti As Integer
  11.     Dim down As NetworkStream
  12.     Dim sock As Socket
  13.  
  14.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15.         Dim thr As New Thread(AddressOf scarica)
  16.         thr.Start()
  17.     End Sub
  18.  
  19.     Public Sub scarica()
  20.         ' File.Delete("C:\casa.zip")
  21.         Dim link As String = "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=it&SrcCategoryId=&SrcFamilyId=5b33b5a8-5e76-401f-be08-1e1555d4f3d4&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f9%2f4%2fd%2f94d3f80a-2c0d-4ce1-a983-52f946b62c78%2fWindowsXP-KB936929-SP3-x86-ITA.exe"
  22.         sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  23.         sock.Connect("colossus.altervista.org", 80)
  24.         down = New NetworkStream(sock)
  25.         Dim byt() As Byte = Encoding.ASCII.GetBytes("GET http://colossus.altervista.org/file/Colossus.zip" & vbCrLf)
  26.         Dim altro As New Thread(AddressOf anco)
  27.         altro.Start()
  28.         down.Write(byt, 0, byt.Length)
  29.         down.Flush()
  30.     End Sub
  31.  
  32.     Public Sub anco()
  33.         While (True)
  34.             Dim ric(1024) As Byte
  35.             sock.Receive(ric, ric.Length, SocketFlags.None)
  36.             Dim str As String = Encoding.ASCII.GetString(ric)
  37.             MsgBox(str)
  38.         End While
  39.     End Sub
  40.  
  41.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  42.         Try
  43.             Label2.Text = Int((quanti / 1024) / 5)
  44.             quanti = 0
  45.         Catch ex As Exception
  46.  
  47.         End Try
  48.     End Sub
  49. End Class



guarda un po che sorpresa.... adesso vediamo se è veloce il nostro ben amato socket puro...

PM Quote
Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo