Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3637

Why am i getting 405 Method Not Allowed while doing a POST Request

$
0
0

I am new to the rest services. I am trying to create a service that accepts json string from a client. I am getting 405 error when I am calling this service using JQuery. Below is the Java code for ws:

This is the way i am posting a request to JERSEY POST RESTFUL Webservice .

var orderinfo = {'ordersplitjson': ordersplitjson, 'customer_id': cust_id , 'homedelivery': homedelivery, 'seatnum' :seatnum , 'locationname':location_nam , 'rownum':rownum}; var json_data =  JSON.stringify(orderinfo);        var ajaxcallquery = $.ajax({            type:'POST',              dataType: 'jsonp',             data: json_data,             contentType: "application/json; charset=utf-8",            url:url+'/OMS/oms1/orderinsertservice',            jsonpCallback:'jsonCallback',            jsonp:false,            success: function(response)             {            },            error: function(jqxhr, status, errorMsg) {            alert('Failed! '+ errorMsg);        }        }); public class OrdersInsertService {    @POST    @Consumes(MediaType.APPLICATION_JSON)    @Produces("application/json")    public String getData(OrderInfo order,@Context HttpServletResponse serverResponse)    throws JSONException            {         serverResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");            serverResponse.addHeader("Access-Control-Allow-Credentials", "true");            serverResponse.addHeader("Access-Control-Allow-Origin", "*");           serverResponse.addHeader("Access-Control-Allow-Headers", "Content-Type,X-Requested-With");            serverResponse.addHeader("Access-Control-Max-Age", "60");}}package com.util;public class OrderInfo {    String ordersplitjson;    public String getOrdersplitjson() {        return ordersplitjson;    }    public void setOrdersplitjson(String ordersplitjson) {        this.ordersplitjson = ordersplitjson;    }    public String getCustomer_id() {        return customer_id;    }    public void setCustomer_id(String customer_id) {        this.customer_id = customer_id;    }    public String getHomedelivery() {        return homedelivery;    }    public void setHomedelivery(String homedelivery) {        this.homedelivery = homedelivery;    }    public String getSeatnum() {        return seatnum;    }    public void setSeatnum(String seatnum) {        this.seatnum = seatnum;    }    public String getLocationname() {        return locationname;    }    public void setLocationname(String locationname) {        this.locationname = locationname;    }    public String getRownum() {        return rownum;    }    public void setRownum(String rownum) {        this.rownum = rownum;    }    String customer_id;    String homedelivery;    String seatnum;    String locationname;    String rownum;}

Could anybody please let me know how to fix this

enter image description here

I am using Jersey 1 ,When i used your class its giving me a compiltion error in eclipse as hwon in picture

enter image description here


Viewing all articles
Browse latest Browse all 3637

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>