本文介绍了从服务器读取文件并在启动时弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想开发一个应用程序,它可以从服务器读取文件并提供弹出窗口,就像许多防病毒程序在系统启动时在右上角提供的一样.
我需要知道:
我应该为此学习什么?
仅文件IO足以执行此操作吗?

该文件可以是txt格式,需要读取.

谢谢

Hello,

I want to develop an application which reads a file from the server and gives popup window like many antivirus programs give in the right corner at system startup.
I need to know:
What should I study for that?
Is only file IO enough to do this?

The file can be in txt formate which need to be read.

Thanks

推荐答案

string result = "";
try
{
WebProxy proxy = new WebProxy("http://proxy:80/", true);
proxy.Credentials = new NetworkCredential("userId", "password", "Domain");
WebRequest request = WebRequest.Create(http://www.c-sharpcorner.com);
request.Proxy = proxy;
// Send the ''HttpWebRequest'' and wait for response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.IO.Stream stream = response.GetResponseStream();
System.Text.Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader reader = new System.IO.StreamReader(stream, ec);
char [] chars = new Char[256];
int count = reader.Read(chars, 0, 256);
while(count > 0)
{
string str = new String(chars, 0, 256);
result = result + str;
count = reader.Read(chars, 0, 256);
}
response.Close();
stream.Close();
reader.Close();
}
catch(Exception exp)
{
string str = exp.Message;
}


将HTTPS与WebProxy类一起使用
为代理服务器创建WebProxy类实例以传递代理以使用HTTP从Internet下载文件时,代码如下所示:
WebProxy代理=新的WebProxy("http://proxy:80/",true);
但是,当您要从HTTPS下载文件时,此代码将不起作用.您需要使用以下代码为HTTPS创建WebProxy实例:


Using HTTPS with WebProxy Class
When you create a WebProxy class instance for a proxy server to pass proxy to download files from the Internet using HTTP, code looks like this:
WebProxy proxy = new WebProxy("http://proxy:80/", true);
However, this code will not work when you want to download a file from HTTPS. You need to use the following code to create a WebProxy instance for HTTPS:

WebProxy myProxy = new WebProxy("server.https.com", 443);



希望能帮助您..问候..



hope that helps you .. regards..


这篇关于从服务器读取文件并在启动时弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 06:47