(Winform)请求的url长度过长怎么办?

Harvey_He 2009-07-02 04:55:49
winform里面的一个功能请求一个页面返回的信息,现在传递的参数长度超过了2048时,就会出异常,该怎么解决,我的原来的代码是这样的,听说web开发里面可以用post,但是Win form里面有解决的方法吗?

string Url="www.demo111.com?fjda=..........//"(长度超过2048)
WebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

response = request.GetResponse();
}

...全文
1023 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Harvey_He 2009-07-06
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 neil198 的回复:]
C# code

Uri uri=new Uri(url);
HttpWebRequest request= (HttpWebRequest)WebRequest.Create(uri);//此处只是URL不带参数request.Method="POST";byte[] buffer=this._defaultEncoding.GetBytes(requestString);//requestString是你的参数request.ContentLength= buffer.Length;//设置数据长度Stream stream= request.GetRequestStream();
stream.Write(buffer,0,buffer.Length);
stream.Close();
HttpWebResponse response= (HttpWebResponse)request.GetResponse();
........
POST数据中如果有中文或者特殊符号需要进行URL编码。如参数为a=我是参数。  a=不用进行编码,我是参数进行URL编码
[/Quote]

谢谢,我实验下
Neil198 2009-07-06
  • 打赏
  • 举报
回复


Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);//此处只是URL不带参数
request.Method = "POST";
byte[] buffer = this._defaultEncoding.GetBytes(requestString);//requestString是你的参数
request.ContentLength = buffer.Length;//设置数据长度
Stream stream = request.GetRequestStream();
stream.Write(buffer,0,buffer.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
........

POST数据中如果有中文或者特殊符号需要进行URL编码。如参数为a=我是参数。 a=不用进行编码,我是参数进行URL编码
Neil198 2009-07-03
  • 打赏
  • 举报
回复
POST提交就可以了。我POST整个XML的数据都没问题
evaa006 2009-07-03
  • 打赏
  • 举报
回复
把你的URL搞短啊,。。。。
Harvey_He 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 kkun_3yue3 的回复:]
晕了.URL后边都跟着些啥参数呀,能不能删点...哈哈笨办法了
这么长的URL你直接放浏览器里看看支持解析啵!
[/Quote]
放IE,safari里面都不行,跳转到该网站页面,说url太长
kangbo818 2009-07-03
  • 打赏
  • 举报
回复
up
yangqiwen1985 2009-07-03
  • 打赏
  • 举报
回复
up
kkun_3yue3 2009-07-03
  • 打赏
  • 举报
回复
晕了.URL后边都跟着些啥参数呀,能不能删点...哈哈笨办法了
这么长的URL你直接放浏览器里看看支持解析啵!
Harvey_He 2009-07-03
  • 打赏
  • 举报
回复
Harvey_He 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhujiechang 的回复:]
用post可以上传几M。不过也不能太大
[/Quote]
我也没有很长,也就2500个字符
Harvey_He 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kkun_3yue3 的回复:]
把参数从URL中分离出来,具体参考楼上网址
[/Quote]
string Url="www.demo111.com?fjda=..........//"(长度超过2048)
WebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
response = request.GetResponse(); //还是异常,说的网站显示url太长
}

另外HttpUtility.UrlEncode这个不能用,是智能设备开发,没有相应的命名空间
zhujiechang 2009-07-02
  • 打赏
  • 举报
回复
用post可以上传几M。不过也不能太大
kkun_3yue3 2009-07-02
  • 打赏
  • 举报
回复
把参数从URL中分离出来,具体参考楼上网址
kkun_3yue3 2009-07-02
  • 打赏
  • 举报
回复
参考
比较详细!
hubro 2009-07-02
  • 打赏
  • 举报
回复
winform 也有POST
request.Method = "POST";

110,590

社区成员

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

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

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