Project

General

Profile

Get a 405 Method Not Allowed error on trying to create an issue through API in C#

Added by Jon Lumpkin almost 12 years ago

We are running 1.0.1, so that may be the issue, but according to the docs, I should still be able to at least post a new issue.

I am trying something very simple, here is my code:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://username:password@server:8080/redmine/issues.xml");
//request.Credentials = new NetworkCredential("username", "password"); // also tried this way
request.Method = "PUT";
request.ContentType = "application/xml";
request.Accept = "application/xml";

string newIssue = "" +
"POST /issues.xml" +
"" +
"<issue>" +
"<subject>Test Issue</subject>" +
"<project_id>myproject</project_id>" +
"</issue>";

byte[] bytes = UTF8Encoding.UTF8.GetBytes( newIssue );

using (Stream putStream = request.GetRequestStream( ) ) {
putStream.Write( bytes, 0, bytes.Length );
}

using( HttpWebResponse response = request.GetResponse( ) as HttpWebResponse ) {
StreamReader reader = new StreamReader( response.GetResponseStream( ) );
Console.WriteLine( reader.ReadToEnd( ) );
}

When I get to request.GetResponse(), I get a 405 Method Not Allowed error.

I also tried doing this as a JSON request, and would get a 500 error instead.

Is it due to our version? Or am I doing something wrong?


Replies (2)

RE: Get a 405 Method Not Allowed error on trying to create an issue through API in C# - Added by Etienne Massip almost 12 years ago

request.Method should be 'POST' and you don't have to prepend the request body with "POST /issues.xml".

RE: Get a 405 Method Not Allowed error on trying to create an issue through API in C# - Added by Jon Lumpkin almost 12 years ago

Yup, that did it, as well as a few other minor changes. I thought I had tried all variants of it like that before, but this worked.

    (1-2/2)