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 请求期间发生异常 ,,,,又烦又急,就是不知道怎么回事,求高人指点到底那里出错了,最好您测试一下。谢谢了
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 请求期间发生异常 ,,,,又烦又急,就是不知道怎么回事,求高人指点到底那里出错了,最好您测试一下。谢谢了
byte[] responseData = web.UploadData(url, "POST ", postdata);
你看看这行,把“POST”后面不要有空格就是这样
byte[] responseData = web.UploadData(url, "POST", postdata);
想要查看异常信息,应该把InnerException都看到。“在 WebClient 请求期间发生异常”这一句话说明不了什么,要看其InnerException属性中显示的具体异常信息。