2016-03-08 56 views
1

我试图重新打开使用MantisConnect解决或关闭的螳螂问题 我已经成功地更改了未解决/已关闭问题的状态,但是当问题是这两个问题之一时,以下例外:使用MantisConnect恢复螳螂问题

System.ServiceModel.ProtocolException 

与消息:

有与从网络接收到的XML的问题。 有关更多详细信息,请参阅内部例外。

与内异常:

System.Xml.XmlException 

随着消息:

在声明的编码 'ISO-8859-1' 不匹配文件“的编码UTF- 8' 。

我使用update命令在这里做介绍的更新:https://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl

得到了我的mantisconnect代码从GitHub这里: https://github.com/mantishub/MantisDotNetClient

有趣的是,这些变化对其他国家和即使是已解决和已关闭状态的工作,异常只会在问题已解决或关闭时抛出 我无法在mantisconnect中找到任何其他命令来重新打开问题,任何人都有一个想法。

编辑: 螳螂的问题,我在我的评论谈论票:https://mantisbt.org/bugs/view.php?id=16579

+0

服务器日志中有任何东西吗?听起来像是在服务器端触发错误,可能是因为缺少重新开放问题的权限 –

+0

由于我们的IT团队采用了令人敬畏的安全措施,所以不幸的是,此时不具备对这些日志的访问权限。我希望尽快改变这一点。我在一两天前遇到过mantisConnect错误跟踪问题,我相信这个问题正在讨论中。我会尽快发布。与此同时,我相信这是我的错误(我打开票的方式),因为我尝试上传mantisconnect时附带的fileName已存在于螳螂问题 – ImP

+0

@ RobertMunteanu我用查尔斯来监视交通,发现以下回应:acces denied,issue is readonly。然而,我可以在螳螂本身重新开放这个问题。这对应于[问题](https://wiki.mantisbt.org/bugs/view.php?id=16579)我发现 – ImP

回答

0

由于是螳螂API在我导航使用WebRequests的网站,并从螳螂散装UP_STATUS功能解决了这个问题的错误。它很脏,但它的工作原理。

class MantisWebRequest 
{ 
    public string Password { private get; set; } 
    public string Username { private get; set; } 

    public CookieContainer CookieContainer { get; private set; } 
    public StreamReader Reader { get; private set; } 
    public Stream DataStream { get; private set; } 
    public WebResponse Response { get; private set; } 
    public HttpWebRequest Request { get; private set; } 
    public string Page { get; private set; } 
    public MantisWebRequest(string username, string password) 
    { 
     Username = username; 
     Password = password; 
     CookieContainer = new CookieContainer(); 
    } 

    public void Connect(string cookieName = null) 
    { 
     string loginurl = "http://mantispageurl/login.php"; 
     // Create a request using a URL that can receive a post. 
     Request = (HttpWebRequest)System.Net.WebRequest.Create(loginurl); 
     // Set the Method property of the request to POST. 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 

     if (cookieName != null) 
      CookieContainer.Add(new Cookie(cookieName, Username, "/", new Uri(loginurl).Host)); 
     Request.CookieContainer = CookieContainer; 

     // Create POST data and convert it to a byte array. Modify this line accordingly 
     string postData = String.Format("username={0}&password={1}&secure_session=on", Username, Password); 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     // Get the response. 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 


    } 

    private void POST(string url, string postData) 
    { 
     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 
     Request.CookieContainer = CookieContainer; 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 
    } 

    private void POST(string url, string postData, string tokenName) 
    { 
     string token = GetToken(tokenName); 

     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 
     Request.CookieContainer = CookieContainer; 

     postData = string.Format("{0}={1}&{2}", tokenName, token, postData); 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 
    } 

    private void GET(string url) 
    { 


     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "GET"; 
     Request.CookieContainer = CookieContainer; 

     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 

    } 

    private string GetToken(string tokenName) 
    { 
     int tokenIndex = Page.IndexOf(tokenName); 
     int endindex = tokenIndex + Page.Substring(tokenIndex).IndexOf(">", StringComparison.Ordinal); 
     int startindex = Page.Substring(0, tokenIndex).LastIndexOf("<", StringComparison.Ordinal); 
     string input = Page.Substring(startindex, endindex - startindex + 1); 

     string valuestring = "value=\""; 
     int tokenIndex2 = input.IndexOf(valuestring, StringComparison.Ordinal); 
     int endindex2 = tokenIndex2 + valuestring.Length + input.Substring(tokenIndex2 + valuestring.Length).IndexOf("\"", StringComparison.Ordinal); 
     int startindex2 = tokenIndex2 + valuestring.Length; 
     string output = input.Substring(startindex2, endindex2 - startindex2); 

     return output; 
    } 

    public void UpdateStatus(int[] issueIds, int statusId) 
    { 
     string tokenName = "bug_actiongroup_UP_STATUS_token"; 
     string formUrl = GetUpdateStatusUrl(issueIds); 
     string formPostDataUrl = "http://mantispageurl/bug_actiongroup.php"; 
     string formPostData = GetUpdateStatusPostData(issueIds, statusId); 

     GET(formUrl); 
     POST(formPostDataUrl, formPostData, tokenName); 
    } 

    private string GetUpdateStatusUrl(int[] issueIds) 
    { 
     string postData = "?"; 
     foreach (var issueId in issueIds) 
     { 
      postData = string.Format("{0}&bug_arr%5B%5D={1}", postData, issueId); 
     } 
     postData = String.Format("{0}&action=UP_STATUS", postData); 

     return "http://mantispageurl/bug_actiongroup_page.php" + postData; 
    } 

    private string GetUpdateStatusPostData(int[] issueIds, int statusId) 
    { 
     string postData = "action=UP_STATUS"; 
     foreach (var issueId in issueIds) 
     { 
      postData = string.Format("{0}&bug_arr%5B%5D={1}", postData, issueId); 
     } 
     postData = String.Format("{0}&status={1}&bugnote_text=", postData, statusId); 

     return postData; 

    }