1

As I need to send data through post for initiating the API, but getting get not supported error. Even I'm using post method ,Please suggest where I did mistake. I have tried OkHTTPClient and HTTPsURL connection, still getting same error

Error: **{"timestamp":"2021-03-23T06:26:43.508+0000","status":405,"error":"Method Not Allowed","message":"Request method 'GET' not supported","path":"/stsBankResponse/"}**

When I directly hit the URL in browser that time also getting method not allowed ,its valid error but programmatically using Post only even though same error

JSONObject jsobj=new JSONObject();
        jsobj.put("authmode", "Abc");
        JSONArray jaarray = new JSONArray();
        jaarray.put(jsobj);
        JSONObject mainObj = new JSONObject();
        mainObj.put("bankResponseDtl", jaarray);
        String str_jsonparams = String.valueOf(mainObj);
        System.out.println("PU_Auth str_jsonparams->"+str_jsonparams);
        String proxyhost=common_utility.getProxyHost();
        String proxyport=common_utility.getProxyPort();
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyhost, new Integer(proxyport)));
        
                OkHttpClient client = new OkHttpClient();
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                builder.connectTimeout(30, TimeUnit.SECONDS); 
                builder.readTimeout(30, TimeUnit.SECONDS); 
                builder.writeTimeout(30, TimeUnit.SECONDS); 
                builder.proxy(proxy);
                client = builder.build();
        RequestBody body = RequestBody.create(JSON, str_jsonparams);
        Request request = new Request.Builder()
     
                .url(common_utility.getEmandateServerResponeURL())
                .post(body)
                .build();

        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                call.cancel();
                System.out.println("ECEEEEE"+e);
            }
@Override
            public void onResponse(Call arg0, Response arg1) throws IOException {
            }
        });
pallavi
  • 11
  • 2
  • Anyone can response – pallavi Mar 23 '21 at 07:50
  • The error you get comes from the web server and is therefore totally unrelated to the used programming language or http client. If the URL you request does not support GET then you can't make a GET request. If it is a web page use browser development tool to see what HTTP request (POST, PUT, DELETE, or whatever) is required or check the API documentation of the used web API provided by the server. – Robert Mar 23 '21 at 12:49
  • Is it possible a redirect is happening? Try adding logging via an event listener https://stackoverflow.com/a/66398516/1542667 – Yuri Schimke Mar 23 '21 at 20:10
  • url will accept only post method, so im also using post method only to send data then whether any mistake in code – pallavi Mar 24 '21 at 09:14

0 Answers0