Results 1 to 5 of 5
  1. #1
    ShikhaMaji is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Sending request to HttpUrlConnection: Status 405 error method not allowed

    Hi ,

    My web application is deployed on my machine . I can access thru Url and access the API's .
    But when I am trying to access the API thru Java code,HTTP 405 Status Error: Method not Allowed comes up.

    The request will be in this form:
    <User.Login>
    <Username>abc</Username>
    <Password>XYZ</Password>
    <Encryption>1</Encryption>
    </User.Login>

    url : http://127.0.1.11:5555/IDXWeb/TestService.htm

    My java code is like this :
    package gepoc;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLEncoder;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;

    public class Main {

    public static void main(String args[]) {

    try {
    String content = "<User.Login>\n";
    content += "<Username>abc</Username>\n";
    content += "<Password>XYZ</Password>\n";
    content += "</User.Login>";

    System.out.println(content);
    byte[] bytes = content.getBytes();
    URL urlServer = new URL("http://127.0.1.11:5555/IDXWeb/TestService.htm");
    HttpURLConnection connection = (HttpURLConnection) urlServer.openConnection();
    connection.setAllowUserInteraction(false);
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-Length", String.valueOf(bytes.length));
    connection.connect();
    OutputStream out = connection.getOutputStream();
    out.write(bytes);
    out.close();
    int code = connection.getResponseCode();
    String msg = connection.getResponseMessage();
    if (code == HttpURLConnection.HTTP_OK) {

    }
    connection.disconnect();
    } catch (MalformedURLException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }catch (IOException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.S EVERE, null, ex);
    }
    }

    I am not able to find out what is getting wrong here. As the application is on my machine and I can access the URL.
    Please help me.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Sending request to HttpUrlConnection: Status 405 error method not allowed

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    ShikhaMaji is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Sending request to HttpUrlConnection: Status 405 error method not allowed

    not sure about the db as its application server which is remotely access throu VPN.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Sending request to HttpUrlConnection: Status 405 error method not allowed

    What db?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Sending request to HttpUrlConnection: Status 405 error method not allowed

    Quote Originally Posted by DarrylBurke View Post
    What db?

    db
    He he :)

    "G'day mate!"
    "I ain't yer mate, mate." etc. etc.


    > connection.setRequestMethod("POST");
    Apparently that particular URL does not allow POST requests. When you just open an URL in a browser it will be a GET request.

Similar Threads

  1. Replies: 2
    Last Post: 06-01-2013, 01:52 PM
  2. HttpURLconnection POST request
    By chopficaro in forum Advanced Java
    Replies: 12
    Last Post: 05-21-2012, 03:10 AM
  3. HTTP POST Request (HttpURLConnection)
    By Dude in forum Networking
    Replies: 17
    Last Post: 07-16-2011, 12:11 AM
  4. POST request using HttpUrlConnection
    By turk in forum Networking
    Replies: 3
    Last Post: 07-06-2011, 05:36 PM
  5. POST request using HttpUrlConnection
    By turk in forum Networking
    Replies: 2
    Last Post: 07-06-2011, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •