windows Mobile 发送HTTP Post请求 问题

KaedeV 2008-04-03 08:39:53
下面是代码
当程序执行到,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();
}
}
}
...全文
332 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sobug 2008-06-12
  • 打赏
  • 举报
回复
我也有这个问题~顶
KaedeV 2008-04-03
  • 打赏
  • 举报
回复
大侠 帮帮哦
KaedeV 2008-04-03
  • 打赏
  • 举报
回复
在 System.IO.IOException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.Net.Sockets.SocketException 中第一次偶然出现的“System.dll”类型的异常
线程 0xb6863bc2 已退出,返回值为 0 (0x0)。
在 System.Net.WebException 中第一次偶然出现的“System.dll”类型的异常
KaedeV 2008-04-03
  • 打赏
  • 举报
回复
有这个异常
在 System.Net.WebException 中第一次偶然出现的“System.dll”类型的异常
nihao38 2008-04-03
  • 打赏
  • 举报
回复
up
KaedeV 2008-04-03
  • 打赏
  • 举报
回复
补充 这个例程 我在 PC机下 已经跑通了,查看MSDN 以上方法都被 wm支持

问题出在什么地方呢?

7,657

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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