C# 使用ManDisconnect重新打开螳螂问题
我正在尝试使用ManDisconnect重新打开已解决或已关闭的螳螂问题 我已成功地更改了未解决/已解决问题的状态,但当问题是这两个问题之一时,我不断得到以下异常:C# 使用ManDisconnect重新打开螳螂问题,c#,.net,mantis,C#,.net,Mantis,我正在尝试使用ManDisconnect重新打开已解决或已关闭的螳螂问题 我已成功地更改了未解决/已解决问题的状态,但当问题是这两个问题之一时,我不断得到以下异常: System.ServiceModel.ProtocolException System.Xml.XmlException 我谨此致辞: 从网络接收的XML有问题。 有关详细信息,请参阅内部异常 除了内部例外: System.ServiceModel.ProtocolException System.Xml.XmlExce
System.ServiceModel.ProtocolException
System.Xml.XmlException
我谨此致辞:
从网络接收的XML有问题。
有关详细信息,请参阅内部异常
除了内部例外:
System.ServiceModel.ProtocolException
System.Xml.XmlException
我谨此致辞:
声明“ISO-8859-1”中的编码与文档“utf-8”的编码不匹配
我正在使用update命令执行此处描述的更新:
从github获取我的ManDisconnect代码:
有趣的是,对其他状态的更改,甚至对已解决和已关闭状态的更改都有效,只有在问题已解决或已关闭时才会抛出异常
我在ManDisconnect中找不到任何其他命令来重新打开问题,任何人都有想法
编辑:
我在评论中提到的螳螂问题:票据:由于螳螂API中有一个bug,我通过使用WebRequests和螳螂的Bulkup_状态功能导航网站解决了这个问题。它很脏,但能用
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;
}
类MantisWebRequest
{
公共字符串密码{private get;set;}
公共字符串用户名{private get;set;}
公共CookieContainer CookieContainer{get;private set;}
公共StreamReader读取器{get;private set;}
公共流数据流{get;private set;}
公共WebResponse响应{get;private set;}
公共HttpWebRequest请求{get;private set;}
公共字符串页{get;private set;}
公共MantisWebRequest(字符串用户名、字符串密码)
{
用户名=用户名;
密码=密码;
CookieContainer=新CookieContainer();
}
公共空连接(字符串cookieName=null)
{
字符串loginurl=”http://mantispageurl/login.php";
//使用可以接收帖子的URL创建请求。
Request=(HttpWebRequest)System.Net.WebRequest.Create(loginurl);
//将请求的Method属性设置为POST。
Request.Method=“POST”;
Request.KeepAlive=true;
如果(cookieName!=null)
添加(新Cookie(cookieName,用户名,“/”,新Uri(loginurl.Host));
Request.CookieContainer=CookieContainer;
//创建POST数据并将其转换为字节数组。相应地修改此行
string postData=string.Format(“用户名={0}&password={1}&secure_session=on”,用户名,密码);
byte[]byteArray=Encoding.UTF8.GetBytes(postData);
//设置WebRequest的ContentType属性。
Request.ContentType=“application/x-www-form-urlencoded”;
//设置WebRequest的ContentLength属性。
Request.ContentLength=byteArray.Length;
//获取请求流。
DataStream=Request.GetRequestStream();
//将数据写入请求流。
写入(byteArray,0,byteArray.Length);
//关闭流对象。
DataStream.Close();
//得到回应。
Response=Request.GetResponse();
//获取包含服务器返回的内容的流。
DataStream=Response.GetResponseStream();
//使用StreamReader打开流以便于访问。
Reader=新的StreamReader(数据流);
//阅读内容。
Page=Reader.ReadToEnd();
//清理溪流。
Reader.Close();
DataStream.Close();
Response.Close();
}
私有void POST(字符串url、字符串postData)
{
Request=(HttpWebRequest)System.Net.WebRequest.Create(url);
Request.Method=“POST”;
Request.KeepAlive=true;
Request.CookieContainer=CookieContainer;
byte[]byteArray=Encoding.UTF8.GetBytes(postData);
//设置WebRequest的ContentType属性。
Request.ContentType=“application/x-www-form-urlencoded”;
//设置WebRequest的ContentLength属性。
Request.ContentLength=byteArray.Length;
//获取请求流。
DataStream=Request.GetRequestStream();
//将数据写入请求流。
写入(byteArray,0,byteArray.Length);
//关闭流对象。
DataStream.Close();
Response=Request.GetResponse();
//获取包含服务器返回的内容的流。
DataStream=Response.GetResponseStream();
//使用StreamReader打开流以便于访问。
Reader=新的StreamReader(数据流);
//阅读内容。
Page=Reader.ReadToEnd();
//清理溪流。
Reader.Close();
DataStream.Close();
Response.Close();
}
私有void POST(字符串url、字符串postData、字符串tokenName)
{
字符串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}”,标记名,标记,postData);
byte[]byteArray=Encoding.UTF8.GetBytes(postData);
//设置WebRequest的ContentType属性。
Request.ContentType=“application/x-www-form-urlencoded”;
//设置WebRequest的ContentLength属性。
Request.ContentLength=byteArray.Length;
//获取请求流。
DataStream=Request.GetRequestStream();
//将数据写入请求流。
写入(byteArray,0,byteArray.Length);
//关闭流对象。
DataStream.Close();
Response=Request.GetResponse();
//获取包含服务器返回的内容的流。
数据流=响应