windows Mobile 发送HTTP Post请求 问题
下面是代码
当程序执行到,Stream newStream = request.GetRequestStream();会抛出未知异常
为什么呢?难道wm不能获取request流?
谢谢大虾指点
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace HTTPThreadMobile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
new System.Threading.Thread(threadFunction).Start();
}
//委托
delegate void threadFunctionDelegate();
//button1事件处理,主要程序
private void threadFunction()
{
//界面线程 委托 给自定义线程
if (this.msgList.InvokeRequired)
{
this.msgList.Invoke(new threadFunctionDelegate(threadFunction));
return;
}
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(this.URLTxt.Text);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
doRequest(request);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
doResponse(response);
}
//响应处理
private void doResponse(HttpWebResponse response)
{
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
String data = reader.ReadToEnd();
this.msgList.Items.Add(data);
reader.Close();
}
//发送Post请求
private void doRequest(HttpWebRequest request)
{
ASCIIEncoding encoding = new ASCIIEncoding();
String data = "name=Allen&com=Neusoft";
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(encoding.GetBytes(data), 0, data.Length);
newStream.Close();
}
}
}