怎么获不得返回值呢??...总出错..
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 ConsoleApplication3
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
string url= "http://61.156.3.58/test.jsp ";
string md5= " ";
string content= "COMMANDID=01&CORPID=40068887807&CPPW= "+md5+ "&SOURCEADDRFLAG=1&PHONE=13156160733&SENDTIME=2006-10-20 17:25:00&TITLE=smstitle&CONTENT=smstest! ";
Class1 post=new Class1 ();
string con=post.postget (url,content);
}
public string postget(string url, string content)
{
try
{
Encoding encoding = Encoding.GetEncoding( "GB2312 ");
byte[] data = encoding.GetBytes(content);
// 准备请求...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "POST ";
myRequest.ContentType= "application/x-www-form-urlencoded ";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// 发送数据
newStream.Write(data,0,data.Length);
newStream.Close();
//接收数据
HttpWebResponse webResponse=(HttpWebResponse)myRequest.GetResponse();
//Console.WriteLine ( "aa ");
Stream stream=webResponse.GetResponseStream();
//System.IO.StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding( "GB2312 "));
StreamReader streamReader=new StreamReader (stream);
string content1 = streamReader.ReadToEnd();
// 关闭相关对象
//Console.WriteLine (content1);
return content1;
streamReader.Close();
webResponse.Close();
}
catch (Exception e)
{
Console.WriteLine ( "error:{0} "+e.ToString ());
}
}
}
}
我想获得一个返回的值怎么就是不行呢,原来返回是void,现在怎么总出错呢.咋回事??
------解决方案--------------------streamReader和webResponse要定义在try的外面