//组合xml内容
StringBuilder strBuilder = new StringBuilder();
var par= @"
strBuilder.Append(par);
string data = strBuilder.ToString();
//进行utf-8编码
var encoding = Encoding.GetEncoding("utf-8");
byte[] buffer = encoding.GetBytes(data);
//根据webURL创建HttpWebRequest对象
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "post";
//request.Headers.Add("charset:utf-8");
request.ContentLength = buffer.Length;
request.ContentType = "text/xml";
StreamWriter myWriter = null;
try
{
myWriter = new StreamWriter(request.GetRequestStream());
myWriter.Write(data);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
myWriter.Close();
}
//读取服务器返回的信息
HttpWebResponse objResponse = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
string result = string.Empty;
result = sr.ReadToEnd();
Console.WriteLine(result);
var resultStr = XElement.Parse("result");
var result\_code = resultStr.Element("return\_code").Value;
var result\_msg = resultStr.Element("return\_msg").Value;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章