读书人

帮忙看看如何接受不到数据呢?在屏幕上

发布时间: 2012-01-19 20:57:58 作者: rapoo

帮忙看看怎么接受不到数据呢?在屏幕上显示不出来呢.这是怎么回事.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Net ;
using System.IO ;
using System.Text ;
using System.Text.RegularExpressions;
using System.Web ;

namespace WindowsApplication5
{
public class Post
{
public static void Main(string [] args)
{
Post zhucheng=new Post();
zhucheng.zhuchengxu();

}
public void zhuchengxu()
{
try
{
ASCIIEncoding encoding=new ASCIIEncoding();
string postData= "COMMANDID=05 ";
byte[] data = encoding.GetBytes(postData);
// Prepare web request
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create( "http://61.156.3.58/test.jsp ");
myRequest.Method = "POST ";
myRequest.ContentType= "application/x-www-form-urlencoded ";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
HttpWebResponse webResponse=(HttpWebResponse)myRequest.GetResponse();
Stream stream=webResponse.GetResponseStream();
System.IO.StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding( "GB2312 "));
string content = streamReader.ReadToEnd();
// 关闭相关对象
Console.WriteLine (content);
streamReader.Close();
webResponse.Close();
}

catch(Exception ed )
{
Console.WriteLine ( "发生 " + ed.ToString()+ "错误! " ) ;
}
}
}
}


[解决办法]
up
[解决办法]
myRequest.ContentType=

[解决办法]
mark 学习

读书人网 >C#

热点推荐