我用HttpWebRequest进行GET请求某网址,返回错误代码:414 [顶贴有分]

dreamw 2006-12-23 01:55:52
我用HttpWebRequest进行GET请求某网址,返回错误代码:414

然后我在网上查询了一下,这个414代码的解释是这样的:

错误代码:414

414错误是由于请求的 URI 太长,服务器拒绝处理请求而造成的。一般的可能性有:
1)客户端错误地将 POST 请求转换为带有长查询信息的 GET 请求。
2)或者是客户端遇到重定向问题(例如,重定向 URL 的前缀指向自身的后缀)。
3)服务器遭到客户端的攻击,该客户端试图利用那些使用定长缓冲来读取或控制请求 URI 的服务器上的安全漏洞。


有什么好的解决方法吗?

声明:我用来请求其它的网站是没有问题的.
还有一点,我排除第一个可能.
...全文
543 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamw 2006-12-25
  • 打赏
  • 举报
回复
孟老大,用了您的方法变成了

尝试自动重定向的次数太多。

这样的例外程序提示~~
tongshisou 2006-12-25
  • 打赏
  • 举报
回复
同时搜网(www.tongshisou.com)是一个很有创意的搜索网站,是目前最易用,最方便的整合搜索网站,本身不做搜索却把业界的搜索引擎聚合在自己网站中,包括百度,GOOGLE,YAHOO,中搜,爱问,搜狗,奇虎,腾讯搜搜,OPENV,TVIX,有网页 新闻 图片 音乐 视频 地图 工作 餐饮 的搜索,可谓很全哦,搜索起来确实方便,而且很易用,可以把结果同时在一个网页中以分割条形式分开,而且可以分割成2-4个窗口,大家可以一试哦www.tongshisou.com
dreamw 2006-12-25
  • 打赏
  • 举报
回复
我这里的命名空间..

using System;
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;
}
guoweihrh 2006-12-25
  • 打赏
  • 举报
回复
学习
孟子E章 2006-12-25
  • 打赏
  • 举报
回复
AllowAutoRedirect默认就是true .
你的urlStr是什么?
jinta2001 2006-12-25
  • 打赏
  • 举报
回复
up
孟子E章 2006-12-25
  • 打赏
  • 举报
回复
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
试试
dreamw 2006-12-25
  • 打赏
  • 举报
回复
唉...又沉底啦..孟老大,你在哪里呀~~
dreamw 2006-12-25
  • 打赏
  • 举报
回复
谢谢,孟老大..得到HTML源代码啦...谢谢,谢谢...现在就结贴~~~
孟子E章 2006-12-25
  • 打赏
  • 举报
回复
参考
http://support.microsoft.com/kb/895971/zh-cn
试试
lr21shiji 2006-12-25
  • 打赏
  • 举报
回复
关注一下...

友情帮顶..
dreamw 2006-12-25
  • 打赏
  • 举报
回复
被大水淹没啦~~我顶我再顶我奋不顾身的顶.HELP ME~
dreamw 2006-12-24
  • 打赏
  • 举报
回复
对啦,,对方是要SSL协议的..但我也添加了证书了..
chsl918 2006-12-24
  • 打赏
  • 举报
回复
没有遇到过,有可能是Url太长了吧?会不会是网站有什么限制?
dreamw 2006-12-24
  • 打赏
  • 举报
回复
好的,,先谢谢孟佬大先~~


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;
}
孟子E章 2006-12-24
  • 打赏
  • 举报
回复
建议贴你的代码
dreamw 2006-12-24
  • 打赏
  • 举报
回复
咳咳...看来我发贴的不是时候,高手都放假啦...自顶先
dreamw 2006-12-24
  • 打赏
  • 举报
回复
又自顶,再求帮助
Alvin709 2006-12-23
  • 打赏
  • 举报
回复
有可能是防火墙的事..
dreamw 2006-12-23
  • 打赏
  • 举报
回复
自顶...大家帮帮忙~~
加载更多回复(7)

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧