WebClient 请求期间发生异常,急死

初学额 2011-03-15 03:37:48
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
WebClient web = new WebClient();
string url = "http://trans.godict.com/index.php";

string param = "from_content= " + "en_zh" + "&langpair= " + "en_zh";
byte[] postdata = Encoding.ASCII.GetBytes(param);


web.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] responseData = web.UploadData(url, "POST ", postdata);
string htmlString = Encoding.Default.GetString(postdata);

}
}
}



总是提示 在 WebClient 请求期间发生异常 ,,,,又烦又急,就是不知道怎么回事,求高人指点

到底那里出错了,最好您测试一下。谢谢了
...全文
3549 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
看看具体的异常,对方是否有禁止跨站post
初学额 2011-03-15
  • 打赏
  • 举报
回复
感谢! 原来是在网上找的代码有问题,是我自己不仔细,谢谢了!!!
  • 打赏
  • 举报
回复
[Quote=引用楼主 money3000 的回复:]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sy……
[/Quote]

想要查看异常信息,应该把InnerException都看到。“在 WebClient 请求期间发生异常”这一句话说明不了什么,要看其InnerException属性中显示的具体异常信息。
chengjia2284 2011-03-15
  • 打赏
  • 举报
回复
楼主解决了吗?
byte[] responseData = web.UploadData(url, "POST ", postdata);
你看看这行,把“POST”后面不要有空格就是这样
byte[] responseData = web.UploadData(url, "POST", postdata);

110,537

社区成员

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

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

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