0

I stuck in amazing situation while consuming REST operation.

When i run simple java program in IDE then i am able to create HTTP request: 201/Created. SUCCESS. Server receives request

When i put same program in Runtime environment(say Mule), i get 405/Method not Allowed. FAILED. Server does not receive anything

When i run it through Rest Client(some mozilla or chrome plugin), It accepts request 201/created. SUCCESS. Server receives request

On that particular URL, i am getting following Allowed:

Allow: GET, POST

Is this issue with Runtime? or any settings to be done in Runtime environment? or issue in Code?

Following is Code:

        `URL urlRequest = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) urlRequest.openConnection();
        conn.setRequestProperty("Host", "10.91.17.170:81");
        conn.setRequestProperty("User-Agent", "Mozilla/4.0");
        conn.setRequestProperty("Accept", "application/atom+xml;q=0.9,*/*;q=0.8"); 
        conn.setRequestProperty("Accept-Language", "en-us,en;q=0.5");
        conn.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
        conn.setRequestProperty("Keep-Alive", "115");
        conn.setRequestProperty("Connection", "keep-alive");
        conn.setRequestProperty("Access-Control-Allow-Origin", "*");
        conn.setRequestProperty("Content-Type", "application/atom+xml");
        conn.setDoOutput(true);
       
        conn.setRequestMethod("POST");
        
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        wr.writeBytes(requestXML);
        wr.flush();
        wr.close();
        System.out.println("Created Request");
        
        System.out.println("Response Code: "+conn.getResponseCode());
        System.out.println("Response Status: "+conn.getResponseMessage());
        System.out.println("Response Status: "+conn.getContentType());
        System.out.println("Request Method: "+conn.getRequestMethod());
        

`

Unable to get answer on google. Did hit and trials but not successful.

Community
  • 1
  • 1
fatherazrael
  • 5,511
  • 16
  • 71
  • 155

1 Answers1

0

405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.

for details you can see this:

jQuery .ajax() POST Request throws 405 (Method Not Allowed) on RESTful WCF

Community
  • 1
  • 1
  • I am able to create requests using POST method using Simple Java program. I am getting this when i put final build on runtime. I am generating a request XML, in code(not browser), which is input to that operation and sending it through Code only which i have mentioned above. Is there any issue in headers? – fatherazrael May 06 '14 at 05:23