问题描述:

I have done a bit of research on this problem before. I had a look at this question and it didn't help me. Basically I am trying to build a program to help people use a website, and I need to get the recaptcha V2 challenge images from google's recaptcha API. I keep getting a

Specified value has invalid HTTP characters

when attempting to download the stream

 try

{

WebClientEx wc = new WebClientEx(cookieJar);

wc.Headers.Add("Referer", recaptchaframe_url);

wc.Headers.Add("UserAgent:", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");

Stream responsestream = wc.OpenRead("http://www.google.com" + challengeimageurl);

}

catch (Exception ex)

{

MessageBox.Show("This program was unable to download CAPTCHA image" + ex.Message);

}

网友答案:

I was able to get past this error by converting all manually set headers in the webclient to their .NET properties. (eg UserAgernt to HttpRequestHeader.UserAgent. It appears that it's useless to set header names manually.

相关阅读:
Top