0
的How to read XML data from a URL by using vb.NET and save如何讀取XML文件並保存使用的HttpRequest和響應
喜的朋友完全相同的副本希望所有的R做得很好。關於這個問題,我得到了一些建議,但如何實施是困惑。任何人都可以幫助實施,以便解決問題。
Try
Dim strUrl As String = "http://xyz"
Dim wr As HttpWebRequest = CType(WebRequest.Create(strUrl), HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
ws.ContentType = "UTF-8"
Dim str As Stream = ws.GetResponseStream()
Dim inBuf(100000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While
Dim fstr As New FileStream("c:/GetXml.xml", FileMode.OpenOrCreate, FileAccess.Write)
fstr.Write(inBuf, 0, bytesRead)
str.Close()
fstr.Close()
Catch ex As WebException
Response.Write(ex.Message)
End Try
我得到了以下建議提前
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
感謝。
謝謝先生,但我去了流輸入和輸出中給出的另一個解決方案。 – pravakar 2009-10-16 13:03:10
@marc_s,所以你可以要求關閉這個問題,所以我們繼續回答以前的問題? – 2009-10-16 13:16:54
是的先生與webclient文件下載非常感謝,是的,我們可以去以前的一個。 – pravakar 2009-10-16 13:33:15