Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By JohnH
  • 1 Post By JohnH

Thread: Using WebClient for imitation of brawser

  1. #1
    j0sur is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    3
    Reputation
    0

    Using WebClient for imitation of brawser

    Hello,
    I need to imitate some brawser using .net framework's classes. I think, that it can be done by WebClient, but I need to set my custom header like
    Code:
    Accept-Encoding: gzip, deflate
    and in this case I'll get encoded data. How can I decode it? Sanx a lot and sorry for my English.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    Easier done with HttpWebRequest, here you can set AutomaticDecompression property. For manual decompression you can use DeflateStream/GZipStream.
    j0sur likes this.

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    An alternative can also be to inherit a class from WebClient and override GetWebRequest method, where you set AutomaticDecompression for the underlying HttpWebReqest.

  4. #4
    j0sur is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    3
    Reputation
    0
    Quote Originally Posted by JohnH View Post
    Easier done with HttpWebRequest, here you can set AutomaticDecompression property. For manual decompression you can use DeflateStream/GZipStream.
    But if I will use AutomaticDecompression I need to know which encoding will be used. How can I get encoding type in this case?

  5. #5
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    Request the compression type you want.

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    The previous reply was a bit hasty, actually DecompressionMethods is a flags enumeration, the values can be combined as bitwise flags, so you can specify both values using bitwise Or operator (AutomaticDecompression = gzip Or deflate). Also note that when you set AutomaticDecompression the request Accept-Encoding header is set automatically.
    j0sur likes this.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking