Menu

Post is failing with status code 500

Help
2010-03-12
2013-04-23
  • gmparker2000

    gmparker2000 - 2010-03-12

    Great tool!  However, I cannot seem to get anything to work that uses a POST to my redmine (0.9.2).  Using GET to read tasks and such works perfectly.  Whenever I try to post time or create a new issue if fails with a 500 internal server error.  Anyone know what this might be?  Is there a particular log in redmine I could look at to try to find a reason?  I stepped through the source to try to pinpoint the problem but no luck.  The URL being used to hit the server works fine when I try directly in a browser.  Any help appreciated.

     
  • Anonymous

    Anonymous - 2010-03-15

    Hi

    I can confirm, Im also getting same error - http://pastie.org/871154

     
  • Maxim

    Maxim - 2010-04-06

    If you comment out the ContentType setting in HttpHelper (line 251) you'll be able to commit the time. This doesn't fix the multi-part post for a new issue by the way.

     
  • Maxim

    Maxim - 2010-04-23

    The following source patch will solve the issue.

    Index: Nohal.Redmine.Client/RedmineClientForm.cs
    ===================================================================
    --- Nohal.Redmine.Client/RedmineClientForm.cs   (revision 83)
    +++ Nohal.Redmine.Client/RedmineClientForm.cs   (working copy)
    @@ -350,10 +350,19 @@
                         projectId, activityId, issueId, dateTimePicker1.Value.ToString("yyyy-MM-dd"), TextBoxComment.Text, String.Format("{0:0.##}", (double)ticks / 3600), Environment.NewLine), 
                         "Ready to commit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                     {
    -                    redmine.LogTimeForIssue(projectId, issueId, TextBoxComment.Text, (double)ticks / 3600, dateTimePicker1.Value, activityId);
    -                    ResetForm();
    -                    MessageBox.Show("Work logged successfully ", "Work logged", MessageBoxButtons.OK,
    -                                    MessageBoxIcon.Information);
    +                    // Fix: add message in case of failure
    +                    try
    +                    {
    +                        redmine.LogTimeForIssue(projectId, issueId, TextBoxComment.Text, (double)ticks / 3600, dateTimePicker1.Value, activityId);
    +                        ResetForm();
    +                        MessageBox.Show("Work logged successfully ", "Work logged", MessageBoxButtons.OK,
    +                                        MessageBoxIcon.Information);
    +                    }
    +                    catch (Exception ex)
    +                    {
    +                        MessageBox.Show(String.Format("Committing failed, the server responded: {0}", ex.Message),
    +                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    +                    }
                     }
                     else if (shouldIRestart)
                     {
    Index: Nohal.Redmine/HttpHelper.cs
    ===================================================================
    --- Nohal.Redmine/HttpHelper.cs (revision 83)
    +++ Nohal.Redmine/HttpHelper.cs (working copy)
    @@ -254,6 +254,9 @@
                 {
                     request.Method = "POST";
                     request.ContentType = "multipart/form-data; boundary=" + MultipartData.Boundary;
    +
    +                // Quick fix: Posting an issue results in a redirect and the HttpWebRequest repeats the content body of the POST in the GET
    +                request.AllowAutoRedirect = false;
                 }
    
                 if (request.Method == "POST")
    @@ -284,6 +287,10 @@
                 StreamReader sr = new StreamReader(httpWResponse.GetResponseStream(), Encoding.UTF8);
                 string s = sr.ReadToEnd();
                 httpWResponse.Close();
    +
    +            // Fix: Redmine changes its token after login
    +            Redmine.CheckForAuthenticityToken(s);
    +
                 return s;
             }
         }
    Index: Nohal.Redmine/Redmine.cs
    ===================================================================
    --- Nohal.Redmine/Redmine.cs    (revision 83)
    +++ Nohal.Redmine/Redmine.cs    (working copy)
    @@ -193,16 +193,10 @@
                 if (!this.authenticated && !string.IsNullOrEmpty(this.RedmineUser))
                 {
                     //Get authenticity token from the server
    -                XhtmlPage page1 = new XhtmlPage(this.httpHelper.GetWebRequest(this.ConstructUri(LoginRelativeUri)));
    -                XmlNodeList nodes = page1.XmlDocument.GetElementsByTagName("input");
                     AuthenticityToken = String.Empty;
    -                foreach (XmlNode node in nodes)
    -                {
    -                    if (node.Attributes["name"].Value == "authenticity_token")
    -                    {
    -                        AuthenticityToken = node.Attributes["value"].Value;
    -                    }
    -                }
    +                // Fix: Moved to separate method because it needs to be called more than one time
    +                CheckForAuthenticityToken(this.httpHelper.GetWebRequest(this.ConstructUri(LoginRelativeUri)));
    +
                     //Now we can log in
                     string requestData = String.Format(LoginRequest,
                                                        System.Web.HttpUtility.UrlEncode(
    @@ -239,6 +233,24 @@
             }
    
             /// <summary>
    +        /// Checks the specific HTML page for an authenticity token.
    +        /// </summary>
    +        /// <param name="page">A string containing the HTML page to check.</param>
    +        public static void CheckForAuthenticityToken(string page)
    +        {
    +            XhtmlPage page1 = new XhtmlPage(page);
    +            XmlNodeList nodes = page1.XmlDocument.GetElementsByTagName("input");
    +            foreach (XmlNode node in nodes)
    +            {
    +                if (node.Attributes["name"].Value == "authenticity_token")
    +                {
    +                    AuthenticityToken = node.Attributes["value"].Value;
    +                    break;
    +                }
    +            }
    +        }
    +
    +        /// <summary>
             /// Gets the list of all the available projects
             /// </summary>
             /// <returns>List of all the projects available to the user</returns>
    @@ -485,7 +497,7 @@
             {
                 string requestData = String.Format(TimeLogRequest,
                                                    System.Web.HttpUtility.UrlEncode(
    -                                                   new Uri(redmineBaseUri, TimeLogFormRelativeUri).ToString()),
    +                                                   new Uri(redmineBaseUri, String.Format(TimeLogFormRelativeUri, projectId)).ToString()), // Fix: add missing project id
                                                    System.Web.HttpUtility.UrlEncode(issueId.ToString()),
                                                    System.Web.HttpUtility.UrlEncode(date.ToString("yyyy-MM-dd")),
                                                    System.Web.HttpUtility.UrlEncode(String.Format("{0:0.##}", timeSpent)),
    
     
  • Irene L.

    Irene L. - 2010-06-24

    There is a same problem in Redmine 0.9.4. (exception string "HttpWebResponse)request.GetResponse();" in the HttpHelper.cs)
    A new items couldn't be added.
    I suppose the problems are in authorisation or cookies.  but I couldn't fix it.
    Does anybody solved it?    /It would be great/

     
  • Simone

    Simone - 2010-07-09

    Hi, i tried with digimexx's code but the issues is not created.
    The command that is sent is:

    Processing IssuesController#create (for 127.0.0.1 at 2010-07-09 16:01:29) [POST]
      Parameters: {"commit"=>"Crea", "project_id"=>"2c", "action"=>"create", "authenticity_token"=>"", "i
    ssue"=>{"start_date"=>"2010-07-09", "estimated_hours"=>"10", "priority_id"=>"4", "fixed_version_id"=>
    "1", "done_ratio"=>"0", "assigned_to_id"=>"3", "subject"=>"Prova simone", "tracker_id"=>"1", "due_dat
    e"=>"2010-08-10", "status_id"=>"1", "description"=>"segnalazione prova"}, "controller"=>"issues"}
    Redirected to http://localhost:3000/login?back_url=http%3A%2F%2Flocalhost%3A3000%2Fprojects%2F2c%2Fis
    sues
    Filter chain halted as [:check_if_login_required] rendered_or_redirected.
    Completed in 0ms (DB: 0) | 302 Found [http://localhost/projects/2c/issues/create]
    

    I done my test on localhost.

     
  • Maxim

    Maxim - 2010-07-10

    If you send me personal message with your e-mail address I'll mail you my version (source and executable) if you like.

     
  • Anonymous

    Anonymous - 2010-09-14

    I am having the same issue when trying to add an issue. Itterating thru objects works GREAT!

    The request to Redmine URL http://dev-yh:8080/redmine/projects/2/issues/new caused the following exception: The remote server returned an error: (500) Internal Server Error..

     

Log in to post a comment.