API V2 error 405

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
Jeffry
Posts: 2
Joined: Tue Apr 11, 2017 1:09 pm

API V2 error 405

Postby Jeffry » Tue Apr 11, 2017 1:30 pm

hi everyone,
I'm trying to develop an application using angular 2 but, when I try to get the token with mi login info (apikey, userkey, username) the server return a 405 error.
to be more specific, the complete error is:

XMLHttpRequest cannot load https://api-dev.thetvdb.com/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 405.


my code for this si:

Code: Select all

token: Token;
    tvdbUrl = 'https://api-dev.thetvdb.com';
    headers = new Headers({'Content-Type': 'application/json', 'Accept': 'application/json'});
    http: Http;

    constructor(http: Http) {
        this.http = http;

    }

    login(loginInfo: LoginInfo): Observable<Token> {
        return this.http.post(this.tvdbUrl + '/login', loginInfo, {headers: this.headers})
            .map(response => response.json() as Token);
    }


I'm doing something wrong?

Jeffry
Posts: 2
Joined: Tue Apr 11, 2017 1:09 pm

Re: API V2 error 405

Postby Jeffry » Fri Apr 14, 2017 4:51 am

maybe, for some of you it's trivial to solve this cross origin issue but for me isn't.
I really need an and, here :S

JO_MELNIK
Posts: 3
Joined: Sat Jul 21, 2018 11:57 pm
Location: france

Re: API V2 error 405

Postby JO_MELNIK » Sun Jul 22, 2018 1:03 am

Cross-origin resource sharing (CORS) errors can be solved easily.

You cant use xmlhttprequest from your domain to a remote domain such like ( http://not_my_domain.com/....) !

You will always get 405 errors when you use xmlhttprequest in javascript because your script is not on thetvdb.com domain.

Instead of posting/puting ... params and header on, thetvdb.com/login send them in javascript to a php file which is located on your server. This php file should be able to give you the thetvdb.com/login 's JSON result . This php file would be like a bridge. By echoing thetvdb page ...

to be clear, : to log in and get your token, you send your ids with your javascript file to a php file, and this php file send your ids to the tvdb, so the php file gets back your token ... and you can do like that with every API_V2's functions, (ex: rating, consulting episode, series ...)

JO_MELNIK
Posts: 3
Joined: Sat Jul 21, 2018 11:57 pm
Location: france

Re re: API V2 error 405

Postby JO_MELNIK » Sun Jul 22, 2018 1:33 am