开发者

How to read xml file and save using httprequest and response

EXACT DUPLICATE of How to read XML data from a URL by using vb.NET and save


Hi friends hope all r doing well. Regarding this question i got some suggestions, but how to implement 开发者_JS百科is confusion. Can any one help to implement so that the problem can solve.

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

I got following suggestion

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); 
    } 
} 

Thanks in advance.


I answered your question before (How to read XML data from a URL by using vb.NET and save) - what is not good about this suggested approach??

This is in C#, but you should have no trouble converting that to VB.NET:

WebClient wc = new WebClient();
wc.DownloadFile("http://xyz", @"C:\getxml.xml");

and you're done!

Please don't ask the same question over and over and over again - wait for answers, read the answers.

Marc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜