URL格式

Scheme://Host/Path?Query

 

The scheme is the protocol that will be used to transfer data.

 

The host specifies to which server the HTTP request is to be directed. There are several
different formats in which the URL host can be represented.

First, it can be in the typical
domain form, such as:
www.httprecipes.com

 

Second, it can be expressed as an IP address, such as:
127.0.0.1

 

Finally, it can be expressed as a symbol that is resolved in the “hosts” file on the computer,
such as:
localhost

 

 

The path specifies which file to retrieve, or which script to run on the server. The “query”
specifies parameters to be passed to the URL. The query immediately follows the path
delimited by a question mark.If you are passing multiple parameters, separate them with the
ampersand symbol (&).

 

URLs can contain a wide variety of characters; however, there are only certain characters
that you can put directly into a URL. For example, you cannot put a space into a URL.

 

 

You need to conduct three basic steps to read data from a URL. A summary
of these steps is:
• Create a Uri Object
• Open a stream
• Read data from the stream

 

try
{
WebRequest http = HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)http.GetResponse();
Stream stream = response.GetResponseStream();
}
catch(UriFormatException e)

{
Console.WriteLine(“Invalid URL”);
}
catch(IOException e)
{
Console.WriteLine(“Could not connect to URL”);
}

 

StreamReader stream =
new StreamReader(response.GetResponseStream(),
System.Text.Encoding.ASCII );
String result = stream.ReadToEnd();
Console.WriteLine( result );
response.Close();
stream.Close();
return result;

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值