Uses WebRequest and WebResponse. Tests use HTTP and the file protocol

image_pdfimage_print

using System;
using System.IO;
using System.Net;

public class TryWebRequest {
public static void Main(String [] args) {
WebRequest request = WebRequest.Create(“http://www.kutayzorlu.com/java2s/com”);
WebResponse response = request.GetResponse();
Console.WriteLine(“Content length: {0}”, response.ContentLength);
Console.WriteLine(“Content type: {0}
“, response.ContentType);
Console.WriteLine(“Request header count: {0}”, request.Headers.Count);
WebHeaderCollection header = request.Headers;
for (int i = 0; i < header.Count; i++) Console.WriteLine("{0} : {1}", header.GetKey(i), header[i]); Console.WriteLine(); StreamReader input = new StreamReader(response.GetResponseStream()); Console.WriteLine(input.ReadToEnd()); input.Close(); } } [/csharp]

This entry was posted in C# Network. Bookmark the permalink.