Click here to Skip to main content
11,923,517 members (61,111 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET
How I Download The WebPage Content Using winInet.dll
Posted 5-Feb-13 1:29am
Edo Tzumer 5-Feb-13 7:47am
If you are using C#.NET why use winInet.dll?
NeerajGSoft 5-Feb-13 10:32am
because i worked with httpwebrequest and httpwebresponse classes and it giving me runtime exception "Internal Server Error" at the time of response of url....

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In c# you do not need to use winInet.dll directly, there are several .NET classes you can use:
WebClient[^] is a wrapper around wininet and probably easiest to use.

WebRequest[^] and it's descendents will give you more control over creating requests and processing response.

In your case problem seems to be that you need to handle cookies so the server you're connecting to can use session.
WebClient class does not handle cookies by default but you can extend it:
public class WebClientEx : WebClient
    private readonly CookieContainer _Container = new CookieContainer();
    protected override WebRequest GetWebRequest(Uri address)
        WebRequest request = base.GetWebRequest(address);
        HttpWebRequest webRequest = request as HttpWebRequest;
        if (webRequest != null)
            webRequest.CookieContainer = _Container;
        return request;
and use WebClientEx instead of WebClient.
NeerajGSoft 5-Feb-13 10:30am
I tried with webrequest but i'm getting "internal server error" @webresponse object....
sjelen 5-Feb-13 12:37pm
You probably didn't make the request right, so the server responded with 'internal server error'.
Maybe you used bad URL, or forgot to authenticate if needed.
The error is not because you used WebRequest class, but because target server could not process your request.

Why don't you try using WebClient.DownloadString method (
It will download the page as a string.

Or add a code sample so we can see what you're trying and help you find the problem.
NeerajGSoft 5-Feb-13 22:19pm
url="[Cite]=77 So.3d 1094"
Uri urlCheck = new Uri(url);
WebClient wc = new WebClient();
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = wc.OpenRead(urlCheck);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();

This Is My Code To Make A Request To Server........
sjelen 6-Feb-13 7:18am
See the code in updated answer.
NeerajGSoft 6-Feb-13 23:25pm
thank u....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.3 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100