Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

415 Unsupported Media Type for DELETE method #459

Closed
polpan opened this issue Dec 9, 2013 · 11 comments
Closed

415 Unsupported Media Type for DELETE method #459

polpan opened this issue Dec 9, 2013 · 11 comments
Labels

Comments

@polpan
Copy link

polpan commented Dec 9, 2013

Hi,

How can I change Content-Type : text/plain;charset=UTF-8 to application/json;charset=utf-8 for DELETE method in restangular?

Because when I tried to delete, I am getting 415 Unsupported Media Type for DELETE method.

Regards

@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

Most of the times, that's related with Rails and another framework getting crazy when DELETE has payload.

Try #78 (comment) That should fix your problem

Thanks!

@mgonto mgonto closed this as completed Dec 9, 2013
@polpan
Copy link
Author

polpan commented Dec 9, 2013

@mgonto I have tried that, however it didn't solve the issue.

I have added as

     RestangularProvider.setRequestInterceptor(function(elem, operation) {
            if (operation === "remove") {
                alert('oj');
                return undefined;
            }
            return elem;
        })

Content Header from browser

Content-Type:text/plain;charset=UTF-8]

@mgonto mgonto reopened this Dec 9, 2013
@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

That's weird.

I'd recommend then setting $http headers for DELETE with the needed content type or using setDefaultHeaders from Restangular: https://github.com/mgonto/restangular#setdefaultheaders

@polpan
Copy link
Author

polpan commented Dec 9, 2013

Adding the following did help to solve the issue.

RestangularProvider.setDefaultHeaders({'Content-Type': 'application/json'});

Does the above has any repercussions?

Thanks

@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

All your requests by default will be application/json. That’s the only repercussion


Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto (https://twitter.com/mgonto)
Linkedin: http://www.linkedin.com/in/mgonto
Github: https://github.com/mgonto

On Monday, December 9, 2013 at 2:07 PM, Pol wrote:

Adding the following did help to solve the issue.
RestangularProvider.setDefaultHeaders({'Content-Type': 'application/json'});
Does the above has any repercussions?
Thanks


Reply to this email directly or view it on GitHub (#459 (comment)).

@polpan
Copy link
Author

polpan commented Dec 9, 2013

And if I have
RestangularProvider.setDefaultHeaders({'Content-Type': 'application/json'});

Do I need to have the following for PUT method?

  RestangularProvider.setRequestInterceptor(function(elem, operation, what) {
            if (operation === 'put') {
                elem.emp = undefined;
                return elem;
            }
            return elem;
        })

@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

That’s not necesary. That just sets elem.emp for undefined for no reason


Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto (https://twitter.com/mgonto)
Linkedin: http://www.linkedin.com/in/mgonto
Github: https://github.com/mgonto

On Monday, December 9, 2013 at 2:08 PM, Pol wrote:

And if I have
RestangularProvider.setDefaultHeaders({'Content-Type': 'application/json'});
Do I need to have the following for PUT method?
RestangularProvider.setRequestInterceptor(function(elem, operation, what) { if (operation === 'put') { elem.emp = undefined; return elem; } return elem; })


Reply to this email directly or view it on GitHub (#459 (comment)).

@polpan
Copy link
Author

polpan commented Dec 9, 2013

Thanks, one question though, if I would want to set header exclusively for DELETE, I have tried the following

      remove: this.config.withHttpDefaults({method: 'DELETE',
      params: params,
      headers: headers || {'Content-Type' : 'application/json'}}),

But that doesn't have any impact. So is this the correct way or are there any other approach?

Thanks

@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

If you want to set that header exclusively for delete, I’d recomment setting it to $http instead of Restangular where you can do that


Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto (https://twitter.com/mgonto)
Linkedin: http://www.linkedin.com/in/mgonto
Github: https://github.com/mgonto

On Monday, December 9, 2013 at 2:26 PM, Pol wrote:

Thanks, one question though, if I would want to set header exclusively for DELETE, I have tried the following
remove: this.config.withHttpDefaults({method: 'DELETE', params: params, headers: headers || {'Content-Type' : 'application/json'}}),
But that doesn't have any impact. So is this the correct way or are there any other approach?
Thanks


Reply to this email directly or view it on GitHub (#459 (comment)).

@polpan
Copy link
Author

polpan commented Dec 9, 2013

Thanks @mgonto

Regards

@polpan polpan closed this as completed Dec 9, 2013
@mgonto
Copy link
Owner

mgonto commented Dec 9, 2013

No problem :D


Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto (https://twitter.com/mgonto)
Linkedin: http://www.linkedin.com/in/mgonto
Github: https://github.com/mgonto

On Monday, December 9, 2013 at 2:55 PM, Pol wrote:

Thanks @mgonto (https://github.com/mgonto)
Regards


Reply to this email directly or view it on GitHub (#459 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants