当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Specified value has invalid HTTP characters with WebClient download

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: