Get a 405 Method Not Allowed error on trying to create an issue through API in C#
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" +
"<subject>Test Issue</subject>" +
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?
RE: Get a 405 Method Not Allowed error on trying to create an issue through API in C# - Added by Etienne Massip 12 months ago
request.Method should be
'POST' and you don't have to prepend the request body with
RE: Get a 405 Method Not Allowed error on trying to create an issue through API in C# - Added by Jon Lumpkin 12 months 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.