十六进制值0x1F,是无效字符。第1行,第1位

时间:2015-04-16 19:07:04

标签: c# jquery ajax restsharp jql

我得到一些奇怪的不一致结果。这种网络方法之前工作得很好。我只添加了一些UI东西(jquery-ui和twitter-bootstrap)。我尝试删除所有UI的东西,但我仍然得到这个错误。我不确定JIRA服务器是否有问题,或者我是否未正确创建请求。

我已尝试执行以下操作(based on this):

  • 使用System.Web.HttpUtility.HtmlDecode
  • textVar = textVar.Replace((char)(0x1F), ' ').Trim();

然而,两者都没有奏效。

此代码不会引发异常,但C#代码中的var response具有此错误堆栈跟踪。输出:

RestSharp response status: Error -
 HTTP response: Forbidden -
 Forbidden -
 '', hexadecimal value 0x1F, is an invalid character. Line 1, position 1. -
 System.Xml.XmlException: '', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Char[] data, Int32 length, Int32 invCharPos)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
   at System.Xml.Linq.XDocument.Parse(String text)
   at RestSharp.Deserializers.XmlDeserializer.Deserialize[T](IRestResponse response)
   at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw) -

空引用''实际上是其他类似于[US]的其他字符。有什么我可以做的来解决这个问题,或者这似乎是一个JIRA服务器问题?

我的最小化示例:

private static string serverUrl = "https://www.url.com/jira";
private static string baseUrl = "/rest/api/2/";
private static string searchCommand = "search";

public static void QuickTest()
{
    string username = HttpContext.Current.Session["jira_username"].ToString();
    string pw = HttpContext.Current.Session["jira_password"].ToString();

    //also tried hardcoding these values. didn't work either
    //username = "";
    //pw = "";

    //create client     
    RestClient client = new RestClient(serverUrl)
    {
        Authenticator = new HttpBasicAuthenticator(username, pw)
    };
    //create query
    string jql = "assignee=msalim";
    //string jql = "assignee%3Dmsalim"; //didn't work either

    //create request
    var request = new RestRequest();
    request.Resource = Path.Combine(baseUrl, searchCommand);
    request.AddParameter(new RestSharp.Parameter()
    {
        Name = "jql",
        Value = jql,
        Type = ParameterType.GetOrPost
    });

    request.Method = Method.GET;

    //get response
    var response = client.Execute<Issues>(request);
    string errorMessage = string.Format("RestSharp response status: {0} -\n HTTP response: {1} -\n {2} -\n {3} -\n {4} -\n ", response.ResponseStatus, response.StatusCode, response.StatusDescription, response.ErrorMessage, response.ErrorException);
    System.Diagnostics.Debug.WriteLine(errorMessage);
}

此外,我已尝试在我的Firefox浏览器中输入这两个内容并返回预期结果:

https://www.url.com/jira/rest/api/2/search?jql=assignee%3Dmsalim

https://www.url.com/jira/rest/api/2/search?jql=assignee=msalim

1 个答案:

答案 0 :(得分:0)

solution引发了我的问题。我为JIRA尝试了同事的登录名和密码,效果很好。 serverUrl下的服务器禁止我再次登录,因为我提出了很多请求。现在我必须与服务器管理员沟通以解决这个问题。另一件需要注意的事情是,我所做的每个请求都被视为&#34;登录失败&#34;根据JIRA。