asp.net http post接口的问题?
protected void btnLoad_Click(object sender, EventArgs e)
{
//入口地址为:http://125.208.3.12:8888/sms.aspx
string url="http://125.208.3.12:8888/sms.aspx?action=overage&userid=1152&account=111&password=111";
Response.ClearContent();
Response.Write(Post(urll));
Response.End();
}
public string Post(string url)
{
string returnData = null;
try
{
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
Stream postData = webReq.GetRequestStream();
postData.Close();
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
Stream answer = webResp.GetResponseStream();
StreamReader answerData = new StreamReader(answer);
returnData = answerData.ReadToEnd();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return returnData.Trim()+"\n";
}
现在的问题是它return是xml形式的string,我怎样得到它标签里边的值?还有如果post(string url)的url改为入口地址,那参数怎么办,这方法又该怎么写?小生不才,望同业好手指点迷经,小弟在线等..
------解决方案--------------------
C# code
byte[] byts = new byte[Request.InputStream.Length];
Request.InputStream.Read(byts, 0, byts.Length);
string req = System.Text.Encoding.UTF8.GetString(byts);
XmlDocument xml = new XmlDocument();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml ";
xml.LoadXml(req);
XmlNodeList topm = xml.DocumentElement.ChildNodes;
foreach (XmlElement element in topm)
{
if (element.Name.ToLower() == "row")
{
//得到该节点的子节点
XmlNodeList nodelist = element.ChildNodes;
if (nodelist.Count > 0)
{
foreach (XmlNode el in nodelist)//读元素值
{
}
}
}
}