jQuery Ajax POST call with JSON in Rest Web Service Issue

前端 未结 3 1661
生来不讨喜
生来不讨喜 2021-01-14 22:39

I want to post a JSON object from my page to a Rest WS. But when I am posting json through jQuery ajax call as output I am getting a HTML page with \"HTTP Status 405

3条回答
  •  深忆病人
    2021-01-14 22:53

    After lot of googling I have found some solution. Now I am using HTTP-Proxy-Servlet.

    I have crated a java web application with my html page which has the ajax call and from my ajax call I am calling a URL of same domain. Please refer my ajax call.

     $.ajax({
            url: "rest/api/crunchifyService/jsonpost",
            method: "POST",
            data: JSON.stringify(jsonObj),
            dataType: 'json',
            contentType: "application/json",
             success: function(result,status,jqXHR ){
                  //Do something
             },
             error(jqXHR, textStatus, errorThrown){
                 //Do something
             }
        }); 
    

    Now I have done this same domain call mapping with org.mitre.dsmiley.httpproxy.ProxyServlet. Please refer my web xml.

    
        proxy
        org.mitre.dsmiley.httpproxy.ProxyServlet
        
            targetUri
            
        
        
            log
            true
        
    
    
        proxy
        /rest/*
    
    

    Now my ajax is calling this Proxy Servlet and it is redirecting to the CROS destination Rest Web Service.

    Please refer the following URL, you will get more details.

    https://github.com/mitre/HTTP-Proxy-Servlet

提交回复
热议问题