Rest-API always respones with HTTP error code 422 on POST-requests
Added by Lars Meyer almost 10 years ago
Hello,
i tried to use a simple Java-Client to manage the issues of projects in Redmine.
Reading and retrieving data with GET-Requests with the Rest-API were sucsessful. That is okay.
Unfortunaly the Redmine-Server responses on all Post-Request with HTTP Base Authentication
with the error Code 422 : Invalid form authenticity token
I implemented the Authentication like the hint in the issue 3920
[[https://www.redmine.org/issues/3920#note-8]]
I have tried to create issue via Java-Client and with SOAP-UI 5.1.3.
Both ways causes the same HTTP Error Code.
Rest-API is enabled and running.
Any suggestions?
Sample-Java-Code:
try {
URL url = new URL("http://dev_user:dev_pw@redmine-test.sy_home.de/issues");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/xml");
String input = "<?xml version=\"1.0\"?>"
+"<issue>"
+"<project_id>40</project_id>"
+"<subject>Ticket via Rest-API</subject>"
+"<priority_id>2</priority_id>"
+ "</issue>";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Response Java-Client:
Exception in thread "main" java.lang.RuntimeException: Failed : HTTP error code : 422 at pkg_redmine_client.redmine_client_post.main(redmine_client_post.java:38)
Response SOAP-UI 5.1.3:
422 Invalid form authenticity token.
Redmine Enviroment:
Environment: Redmine version 2.4.5.stable Ruby version 1.8.7-p374 (2013-06-27) [x86_64-linux] Rails version 3.2.17 Environment production Database adapter Mysql2 SCM: Subversion 1.8.5 Git 2.0.0 Filesystem Redmine plugins: redmine_hudson 2.1.2 redmine_lightbox 0.0.1 redmine_wiki_extensions 0.6.4