Skip to Content
avatar image
Former Member

Web Ide testing app is sending wrong content type to sap gateway

Hi ,

I have created an app in web ide tool and trying to POST data from app to gateway odata service. I am facing and error 415 (Unsupported Media Type). This is happening due to content type. I have declared the content type in manifest

"headers": {
"X-Requested-With": "X",
"Content-Type": "application/json; charset=utf-8"
},

same header i have set while calling create function

var oEntry = {
        "Matnr" : "100005",
        "Werks" : "X110",
        "Name1" : "PLANT XXXXX",
        "Labst" : "0.000",
        "Insme" : "1134.000",
        "Speme" : "0.000",
        "Meins" : "BOX",
        "Maktx" : "XXXXXX MILLED PLAIN BOX"
};

var oModel = this.getOwnerComponent().getModel("Model declared in manifest");
 oModel.refreshSecurityToken(function() {
  console.log('Succesfully retrieved CSRF Token');
   }, function() {
     console.log('Error retrieving CSRF Token');
     }, false);


 oModel.setHeaders({
	"X-Requested-With": "X",
	"Content-Type": "application/json",
	"accept":  "application/json"
		});

 oModel.create("/Entityet", oEntry,
     {           
        method: "POST",
        success: function(data) {
        alert("success");
         },
        error: function(e) {
         alert("error");
          }
      }
                
     );

error in chrome

error1.jpg

when i put a trace on odata and replay it Content Type is coming as application/x-www-form-urlencoded; charset=UTF-8 instead of application/json.

error2.jpg

Not sure what i am missing in the code.

error1.jpg (49.5 kB)
error2.jpg (126.4 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers