Feature #38495
Updated by Holger Just almost 2 years ago
<pre><code class="java"> public String doPostIssue() throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials( new AuthScope("redmine.org/issues", 80), new UsernamePasswordCredentials("admin", "admin")); HttpPost httpPost = new HttpPost("http://www.redmine.org/issues"); System.out.println("executing request:\n" + httpPost.getRequestLine()); HttpEntity entity = new EntityTemplate(cp); httpPost.setEntity(entity); HttpResponse response = httpclient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); String value = ""; System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (responseEntity != null) { System.out.println("Response content length: " + responseEntity.getContentLength()); value = responseEntity.getContent().toString(); } System.out.println(EntityUtils.toString(responseEntity)); httpclient.getConnectionManager().shutdown(); return value; } ContentProducer cp = new ContentProducer() { public void writeTo(OutputStream outstream) throws IOException { Writer writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write("format=json&action=new&"); String payload = "{\"issue\": {\"subject\": \"New Issue by Eliana\",\"description\": \"Some description\",\"tracker_id\": \"1\",\"priority_id\":\"3\",\"custom_fields\": [{\"id\": \"1\", \"value\": \"" + new Random().nextInt() + "\"}]}}"; writer.write(payload); writer.flush(); } }; </code></pre> I have this response: <pre> POST http://www.redmine.org/issues HTTP/1.1 ---------------------------------------- HTTP/1.1 301 Moved Permanently Response content length: 0 </pre> How should I fix it?