How to ensure that the process webclient / curl process 503, like process 200

If the website pulled 503, then the web client will simply throw an exception.

For example, go to http://www.google.com/sorry/?continue=http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dkucing

If we open it in Internet Explorer, it will open the page. If we use livehttpheader, it returns 503, not 200. However, it still shows something.

Now try spinning the same page.

http://www.google.com/sorry/?continue=http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dkucing

Curl will stop. So, how to make curl treat 503, like 200?

Samples are when we try to find something on Google. Google sometimes requires a captcha. Well, just pop so I can fill in the captcha. But the webclient just throws an exception without assigning the contents to the file. This is not good.

How to ensure that the web client does not throw things away.

The same goes for curl

+2
source share
2 answers

For WebClient you need to handle WebException.Response . For example. this LINQPad query unloads the HTML provided by the Not Found web server webpage:

 Dim wc = New System.Net.WebClient Try Dim rd = wc.DownloadData(New Uri("http://localhost/test")) rd.Dump Catch Ex As System.Net.WebException Dim rs = Ex.Response Call (New StreamReader(rs.GetResponseStream)).ReadToEnd.Dump End Try 

Now actually using WebClient .

0
source

No authority responds to it, so I'll just say CURLOPT_FAILONERROR

Set to false.

I think there is something similar for webclient. Will it answer if someone doesn’t come up with something better.

+2
source

All Articles