我用HttpWebRequest进行GET请求某网址,返回错误代码:414然后我在网上查询了一下,这个414代码的解释是这样的:错误代码:414414错误是由于请求的 URI 太长,服务器拒绝处理请求而造成的。一般的可能性有:
1)客户端错误地将 POST 请求转换为带有长查询信息的 GET 请求。
2)或者是客户端遇到重定向问题(例如,重定向 URL 的前缀指向自身的后缀)。
3)服务器遭到客户端的攻击,该客户端试图利用那些使用定长缓冲来读取或控制请求 URI 的服务器上的安全漏洞。
有什么好的解决方法吗?声明:我用来请求其它的网站是没有问题的.
还有一点,我排除第一个可能.
1)客户端错误地将 POST 请求转换为带有长查询信息的 GET 请求。
2)或者是客户端遇到重定向问题(例如,重定向 URL 的前缀指向自身的后缀)。
3)服务器遭到客户端的攻击,该客户端试图利用那些使用定长缓冲来读取或控制请求 URI 的服务器上的安全漏洞。
有什么好的解决方法吗?声明:我用来请求其它的网站是没有问题的.
还有一点,我排除第一个可能.
=======================用IE登陆没有问题呀.
private string view_site(string urlStr) //下载查看HTML
{
string certUri = Environment.CurrentDirectory.ToString() + "\\certfile\\certFile.cert";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlStr);
X509Certificate store = X509Certificate.CreateFromCertFile(certUri);
myHttpWebRequest.ClientCertificates.Add(store);
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
myHttpWebRequest.CookieContainer = stac.PicContainer;
CookieContainer CkiContainer = new CookieContainer();
myHttpWebRequest.CookieContainer = CkiContainer; HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Cookies = stac.PicContainer.GetCookies(myHttpWebRequest.RequestUri);
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
string htmlText = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return htmlText; } public bool CheckValidationResult(object sender, X509Certificate store, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
myHttpWebRequest.AllowAutoRedirect=true;
试试
你的urlStr是什么?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security.X509;
using System.Security.Authentication;
using System.Net.Security;
//函数..urlStr 是https://esales.16288.com/
private string view_site(string urlStr) //下载查看HTML
{
string certUri = Environment.CurrentDirectory.ToString() + "\\certfile\\certFile.cert";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlStr);
X509Certificate store = X509Certificate.CreateFromCertFile(certUri);
myHttpWebRequest.ClientCertificates.Add(store);
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
myHttpWebRequest.CookieContainer = stac.PicContainer;
CookieContainer CkiContainer = new CookieContainer();
myHttpWebRequest.CookieContainer = CkiContainer; HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Cookies = stac.PicContainer.GetCookies(myHttpWebRequest.RequestUri);
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
string htmlText = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return htmlText; } public bool CheckValidationResult(object sender, X509Certificate store, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
http://support.microsoft.com/kb/895971/zh-cn
试试