我發現這段代碼正在做我想要的東西。它在第三方網站上下載文件,並在流式傳輸時,每個塊都寫入Response中,以便完全模糊原點。因此,可以從任何網站提供任何文件,就好像我擁有它一樣。
Private Sub SendFile(ByVal url As String)
Dim stream As System.IO.Stream = Nothing
Dim bytesToRead As Integer = 10000
Dim buffer() As Byte = New Byte((bytesToRead) - 1) {}
Try
Dim fileReq As System.Net.WebRequest = CType(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest)
Dim fileResp As System.Net.HttpWebResponse = CType(fileReq.GetResponse, System.Net.HttpWebResponse)
If (fileReq.ContentLength > 0) Then
fileResp.ContentLength = fileReq.ContentLength
End If
stream = fileResp.GetResponseStream
Dim resp As System.Web.HttpResponse = HttpContext.Current.Response
resp.ContentType = "application/octet-stream"
resp.AddHeader("Content-Disposition", ("attachment; filename=\""" + ("mp3" + "\""")))
resp.AddHeader("Content-Length", fileResp.ContentLength.ToString)
Dim length As Integer = 1000000
While (length > 0)
If resp.IsClientConnected Then
length = stream.Read(buffer, 0, bytesToRead)
resp.OutputStream.Write(buffer, 0, length)
resp.Flush()
buffer = New Byte((bytesToRead) - 1) {}
Else
length = -1
End If
End While
Catch
stream.Close()
Finally
If (Not (stream) Is Nothing) Then
stream.Close()
End If
End Try
Response.End()
End Sub
我認爲最好的方法是在現有的Flash播放器上製作自定義代碼並使用額外的代碼繼續播放。聽起來有點困難,也許是。 – Aristos
是的。將傳輸函數改爲「低級套接字」算法是我想要避免的,因爲我正在與其他編碼人員合作,他們將在不同的平臺上進行硬編碼定製客戶端,但似乎我目前沒有其他選擇。 –
如果您對@Aristos感興趣,我發現了一種從服務器B下載到服務器A並同時將其發送給客戶端的方法。 –