Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-32788

Can not post JSON data to JSON services

Details

    • Bug
    • Status: Closed
    • Resolution: Won't Fix
    • 6.1.1 CE GA2, 6.1.20 EE GA2
    • 6.1.1 CE GA2, 6.1.20 EE GA2
    • None
    • Standalone REST client or Javascript client or Java client

    Description

      When you invoke a JSON service, it is necessary to pass all data as application/x-www-form-urlencoded. It is not possible to pass JSON object in the post body using application/json.

      For example, if we have data like shown below,

      var data = {
        "serviceMethodName" : "createBar",
        "servletContextName" : "test-json-portlet",
        "serviceParameters" : ["userId","userName"],
        "userId" : 10194,
        "userName" : "test"
      };
      

      Then the following code does not work,

      var url = "http://localhost:8080/api/json";
      									
      $.ajax({
        type : "POST",
        url : url,
        contentType : "application/json; charset=utf-8",
        dataType : "json",
        headers : {
          "Authorization" : "Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0"
        },
        data : JSON.stringify(data),
        success : function(results) {
          console.log(results);
        } 
      });
      

      Attachments

        Activity

          People

            igor.spasic Igor Spasic (Inactive)
            prashantdighe Prashant Dighe (Inactive)
            Kiyoshi Lee Kiyoshi Lee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9 years, 44 weeks, 3 days ago

              Packages

                Version Package
                6.1.1 CE GA2
                6.1.20 EE GA2