如何实现从服务器上将文件拷贝下来 由于需要做在线更新,请问如何实现从服务器上将文件拷贝下来。要求通过两种方式,第一种直接利用file uri 来进行copy。另一种利用http uri来进行copy。主要是做如何通过Http来拷贝。最好利用WCF与服务器通信。请大侠赐教,不胜感激。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没用过WCF,我一般用HttpRequest或WebClient。 你的意思是想,将目标网页内容获取下来吗?如果是可以这样 Try builder = New StringBuilder Dim uri As New Uri(Me.txtURL.Text) builder.Append("AbsolutePath:" & uri.AbsolutePath & ControlChars.CrLf) builder.Append("AbsoluteUri:" & uri.AbsoluteUri & ControlChars.CrLf) builder.Append("Host:" & uri.Host & ControlChars.CrLf) builder.Append("HostNameType:" & uri.HostNameType.ToString() & ControlChars.CrLf) builder.Append("LocalPath:" & uri.LocalPath & ControlChars.CrLf) builder.Append("PathAndQuery:" & uri.PathAndQuery & ControlChars.CrLf) builder.Append("Port:" & uri.Port & ControlChars.CrLf) builder.Append("Query:" & uri.Query & ControlChars.CrLf) builder.Append("Scheme:" & uri.Scheme) Dim request As WebRequest = WebRequest.Create(uri) Dim response As WebResponse = request.GetResponse() builder = New StringBuilder builder.Append("Request type:" & request.GetType().ToString() & ControlChars.CrLf) builder.Append("Response type:" & response.GetType().ToString() & ControlChars.CrLf) builder.Append("Content length:" & response.ContentLength & "bytes" & ControlChars.CrLf) builder.Append("Content type:" & response.ContentType & ControlChars.CrLf) builder.Append("Get HTML code successful! Time:" & DateTime.Now.ToString() & Environment.NewLine & Environment.NewLine) Dim stream As Stream = response.GetResponseStream() Dim reader As New StreamReader(stream, System.Text.Encoding.Default) Dim data As String = reader.ReadToEnd() reader.Close() stream.Close() Me.txtHTML.Text = data Me.txtResult.Text &= builder.ToString() getCW = True Catch ex As Exception builder = New StringBuilder() builder.Append("获取远程Web代码失败:" & ex.Message) builder.Append(" 时间:" & DateTime.Now.ToString()) builder.Append(Environment.NewLine) builder.Append(Environment.NewLine) Me.txtResult.Text &= builder.ToString() getCW = False End Try如果你需要清楚HTML代码 只保留网页内容可以用这个正则表达式来过滤<\/*[^<>]*> 可以 使用 微软的 智能客户端http://dev.rdxx.com/NET/WindowsForms/2005-7/27/120622196_3.shtml roki_chen ,不是这样的,就相当于一个cs结构的在线更新系统,下载文件包 --参考:http://blog.csdn.net/zlp321002/archive/2006/10/31/1359316.aspx storm0912() ( ) 信誉:100 Blog 加为好友 2007-05-18 08:20:13 得分: 0 顶下,做过在先更新的高手帮忙回答下。 ---------------------------------------------------------我就是用WebClient来做在线更新的。其实在这个方案中WCF并不是很好的解决方案。 写过一个类似的程序,实现局域网更新程序(HTTP一样),如果需要请给我发邮件索取。[email protected] c# 多线程 sharpdevelop的功能有多强,可以实际用于项目的开发吗? 请问这是那种加密方式? 一个非常优秀的C#开发工具EasyCSharp 如何再.net中生成dll文件 200分问题:关于Remoting的疑问 How to create to set up the document of *.MSC? C#连接服务器数据库的疑问 初学,请教一个简单简单的问题。 还是ComboBox的问题,请高手指教! 运行到 OleDbDataAdapter .Fill( ds ,"a" );发生异常 谢谢 急,Remoting 故障,在线等!!
Try
builder = New StringBuilder
Dim uri As New Uri(Me.txtURL.Text)
builder.Append("AbsolutePath:" & uri.AbsolutePath & ControlChars.CrLf)
builder.Append("AbsoluteUri:" & uri.AbsoluteUri & ControlChars.CrLf)
builder.Append("Host:" & uri.Host & ControlChars.CrLf)
builder.Append("HostNameType:" & uri.HostNameType.ToString() & ControlChars.CrLf)
builder.Append("LocalPath:" & uri.LocalPath & ControlChars.CrLf)
builder.Append("PathAndQuery:" & uri.PathAndQuery & ControlChars.CrLf)
builder.Append("Port:" & uri.Port & ControlChars.CrLf)
builder.Append("Query:" & uri.Query & ControlChars.CrLf)
builder.Append("Scheme:" & uri.Scheme)
Dim request As WebRequest = WebRequest.Create(uri)
Dim response As WebResponse = request.GetResponse()
builder = New StringBuilder
builder.Append("Request type:" & request.GetType().ToString() & ControlChars.CrLf)
builder.Append("Response type:" & response.GetType().ToString() & ControlChars.CrLf)
builder.Append("Content length:" & response.ContentLength & "bytes" & ControlChars.CrLf)
builder.Append("Content type:" & response.ContentType & ControlChars.CrLf)
builder.Append("Get HTML code successful! Time:" & DateTime.Now.ToString() & Environment.NewLine & Environment.NewLine)
Dim stream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(stream, System.Text.Encoding.Default)
Dim data As String = reader.ReadToEnd()
reader.Close()
stream.Close()
Me.txtHTML.Text = data
Me.txtResult.Text &= builder.ToString()
getCW = True
Catch ex As Exception
builder = New StringBuilder()
builder.Append("获取远程Web代码失败:" & ex.Message)
builder.Append(" 时间:" & DateTime.Now.ToString())
builder.Append(Environment.NewLine)
builder.Append(Environment.NewLine)
Me.txtResult.Text &= builder.ToString()
getCW = False
End Try如果你需要清楚HTML代码 只保留网页内容可以用这个正则表达式来过滤<\/*[^<>]*>
http://blog.csdn.net/zlp321002/archive/2006/10/31/1359316.aspx
顶下,做过在先更新的高手帮忙回答下。
---------------------------------------------------------
我就是用WebClient来做在线更新的。其实在这个方案中WCF并不是很好的解决方案。
[email protected]