【发布时间】:2012-02-01 10:49:44
【问题描述】:
我正在向 Web 服务发送一个 URL 和 XML,以便它会向我返回有关结果的 JSON。我在这里将请求发布到网络服务,我如何从网络服务中获取价值。 Web 服务返回的值是 JSON。这里应该返回什么类型,应该返回什么来获取HTTP响应状态和body
public string HttpPostcredentials(string XML, string url)
{
try
{
HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest;
req.Method = "POST";
byte[] buffer = Encoding.ASCII.GetBytes(XML);
req.ContentLength = buffer.Length;
req.ContentType = "application/xml";
Stream PostData = req.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
}
catch (Exception e)
{
}
return null;
}
【问题讨论】:
-
空的
catch子句是万恶之源。