The articleabs webrequest method output’s id, when the POST request successful, which is forwarded createURL metod. However, I am getting the following error:
Error -> Data at the root level is invalid. Line 1, position 1.
Code line:
var document = XDocument.Parse(articleABS());
I have tried adding in a null statement condition to the createURL method, if the id from the article method is empty then exit the method, but that has not worked either and I am still getting the error.
public string createURL()
{
string uri = "";
var document = XDocument.Parse(articleABS());
var href = document.Descendants("link").Single().Attribute("title").Value;
href = href.Replace("Article", "");
string id = Regex.Match(href, @"\d+").Value;
var result = (@"#####" + id + "/sections");
return uri = result.ToString();
}
public string articleABS()
{
var result = (@"####" + mainID + "/articles");
string URL = result;
string method = "POST";
string postData = articleXML.createArticleABS();
try
{
if (hwrequest.Method == "POST")
{
....
}
using (HttpWebResponse hwresponse = (HttpWebResponse)hwrequest.GetResponse())
{
....
}
hwresponse.Close();
}
}
catch (WebException e)
{
.....
else
{
//
}
}
return responseData;
}
Example output of articleABS();
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://api.newsweaver.com/nwapistatic/ntsa-api.xsl" type="text/xsl"?>
<?xml-stylesheet href="https://api.newsweaver.com/nwapistatic/ntsa-api.css" type="text/css"?>
<status>
<code>409
</code>
<message>
content.article.required.title null
</message>
</status>
Please advise. Thank you