Click here to Skip to main content
Rate this: bad
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 at 5-Feb-13 7:47am
If you are using C#.NET why use winInet.dll?
NeerajGSoft at 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 at 5-Feb-13 10:30am
I tried with webrequest but i'm getting "internal server error" @webresponse object....
sjelen at 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 at 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 at 6-Feb-13 7:18am
See the code in updated answer.
NeerajGSoft at 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
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 479
2 OriginalGriff 360
3 CHill60 280
4 CPallini 250
0 Sergey Alexandrovich Kryukov 10,017
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076

Advertise | Privacy | Mobile
Web02 | 2.8.150327.1 | 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