当我调用Wrequest()方法时,它返回一个XML响应,并在该响应中,我提取一个id号(使用getID()函数)。
当我执行Wrequest()方法时,我得到了id - " 5219479"响应,但是当我执行getID()
方法时,我得到一个新的id" 5219480",而我希望Wrequest()方法将相同的id传递给getID()方法。
public static string WRequest()
{
string URL = "######";
string method = "POST";
string postData = newTemplates.createXMLIssue();
string responseData = "";
int statusCode;
HttpWebRequest hwrequest = (HttpWebRequest)WebRequest.Create(URL);
hwrequest.Timeout = 60000;
hwrequest.Method = method;
hwrequest.KeepAlive = false;
if (hwrequest.Method == "POST")
{
// code
}
// Attempt to receive the WebResponse to the WebRequest.
using (HttpWebResponse hwresponse = (HttpWebResponse)hwrequest.GetResponse())
{
statusCode = (int)hwresponse.StatusCode;
if (hwresponse != null)
{ // If we have valid WebResponse then read it.
using (StreamReader reader = new StreamReader(hwresponse.GetResponseStream()))
{
// XPathDocument doc = new XPathDocument(reader);
// string responseString = reader.ReadToEnd();
if (statusCode == 201)
{
var xmlDoc = XDocument.Load(reader);
var statusXml = xmlDoc.ToString();
responseData = statusXml.ToString();
}
else
{
var xmlDoc = XDocument.Load(reader);
//var statusElement = xmlDoc.Root.Element("status");
var statusXml = xmlDoc.ToString();
responseData = statusXml.ToString();
reader.Close();
}
}
}
hwresponse.Close();
}
return responseData;
}
我的问题是,如何将来自wREquest()方法的相同id响应传递给getID()方法?
public string getID()
{
var document = XDocument.Parse(WRequest());
var href = document.Descendants("link").Single().Attribute("title").Value;
href = href.Replace("Issue", "");
string id = Regex.Match(href, @"\d+").Value;
return id.ToString();
}
这就是我在pageload中执行上述方法的方法,以供进一步参考:
string nm = WRequest();
string em = getID();
Label1.Text = Server.HtmlEncode(nm);
Label2.Text = Server.HtmlEncode(em);
感谢您的时间和帮助。
答案 0 :(得分:0)
您正在调用远程服务器的WRequest()
方法中调用getID()
,我假设它正在为每个处理的呼叫响应一个新ID。
您将需要验证您正在呼叫的服务。
要在问题中执行您想要执行的操作,您需要更改getID()
方法以接受WRequest()
正在返回的XML字符串作为输入并处理该输入以确定ID返回。