Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.
User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Mon Jan 07, 2019 11:38 am

Hi

please read my initial post, there is everything what you need to know.

https://forum.opensubtitles.org/viewtop ... 453#p39771

If you dont know something, ask exactly what you dont know.

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Tue Feb 19, 2019 2:35 pm

Hi,
can you let us specify userAgent directly in url?

For example:

Code: Select all

curl https://rest.opensubtitles.org/search/moviebytesize-750005572/moviehash-319b23c54e9cf314/UserAgent-TemporaryUserAgent

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Tue Feb 19, 2019 7:35 pm

Hi

this is not possible, because of caching (it can not be cached like that in your example)

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Tue Feb 19, 2019 10:04 pm

Thanks for the answer.
I'm trying to search for subtitles using these rest api from a js client and browsers don't allow to change user agent.
Any suggestions??

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Wed Feb 20, 2019 3:50 am

Hi

we understand. Try to set up custom header X-User-Agent and validate using it.
example:

Code: Select all

curl --header "X-User-Agent: TemporaryUserAgent" https://rest.opensubtitles.org/search/query-matrix%20reloaded/sublanguageid-cze

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Wed Feb 20, 2019 2:27 pm

Hi,
I've made the request as follows (using angular):

Code: Select all

this.httpClient .get('https://rest.opensubtitles.org/search/query-' + encodeURIComponent(query), { headers: new HttpHeaders().set('X-User-Agent', 'TemporaryUserAgent') }) .subscribe(result => { console.log(result); });
Now browser perform a preflight request and I get error 403 with this message:

Code: Select all

Access to XMLHttpRequest at 'https://rest.opensubtitles.org/search/query-test' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is the request:

Code: Select all

-[b]General[/b] Request URL: https://rest.opensubtitles.org/search/query-test Request Method: OPTIONS Status Code: 403 Remote Address: 104.25.132.104:443 Referrer Policy: no-referrer-when-downgrade -[b]Response Headers[/b] age: 0 cache-control: private, must-revalidate, post-check=0, pre-check=0, no-store, max-age=0, s-max-age=0, max-stale=0 cf-ray: 4ac0ee7398413dc5-MXP content-encoding: br content-type: text/html; charset=UTF-8 date: Wed, 20 Feb 2019 12:21:10 GMT expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" server: cloudflare status: 403 vary: Accept-Encoding x-cache: MISS x-cache-backend: web3 x-ratelimit-remaining: 39 x-via: fw2.int.opensubtitles.org -[b]Request Headers[/b] Access-Control-Request-Headers: x-user-agent Access-Control-Request-Method: GET Origin: http://localhost:4200 Referer: http://localhost:4200/player/60dbc8e0a28848cc33edd2d1daf9c761 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
What should I do?

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Wed Feb 20, 2019 5:53 pm

Hi,

in our response is
header('Access-Control-Allow-Origin: *');

so you should be ok to call it. Anyway, we add some more headers, try now.

Also make sure, you are calling GET with REST, not method OPTIONS

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Wed Feb 20, 2019 8:24 pm

Thanks for your help, I'll try it later.
Also make sure, you are calling GET with REST, not method OPTIONS
I'm calling a GET with REST, but the automatic OPTION request asks the server if it can receive that custom headers (so it's an OPTION request without user-agent or x-user-agent header).
Here you can read more about preflight requests.

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Thu Feb 21, 2019 2:22 am

ok let us know if it works, and if it doesnt what need to be changed - I assume it is header thing.

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Thu Feb 21, 2019 10:02 am

Hi,
it is still not working.
If you want to simulate browser behaviour you just need to use this curl command:

Code: Select all

curl -H --header "X-User-Agent: TemporaryUserAgent" https://rest.opensubtitles.org/search/query-matrix
It will answer:

Code: Select all

curl: (6) Could not resolve host: X-User-Agent http useragent is not valid
So I suppose that the problem is that your server does not accept an OPTION request with only the following header:

Code: Select all

Access-Control-Request-Headers: x-user-agent Access-Control-Request-Method: GET Origin: http://localhost:4200 Referer: http://localhost:4200/player/60dbc8e0a28848cc33edd2d1daf9c761 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
As you can read from the link in my previous post I cannot control this request because
A preflight request is automatically issued by a browser, when needed. In normal cases, front-end developers don't need to craft such requests themselves.
and the server answer with http useragent is not valid.

The solution should be that your server accept that OPTION request without checking X-User-Agent and User-Agent header and just answer with code 200 and with
header("Access-Control-Allow-Headers: X-User-Agent");
.

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Fri Feb 22, 2019 3:42 am

Hi

ok, will check, thanks for debug.

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Sat Feb 23, 2019 5:41 am

ok I applied quick fix, can you check now ?

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Sat Feb 23, 2019 12:34 pm

ok I applied quick fix, can you check now ?
Hi,
it is still not working, but now I have a different error.

Code: Select all

Request URL: https://rest.opensubtitles.org/search/query-matrix Request Method: OPTIONS Status Code: 404 Remote Address: 104.25.132.104:443 Referrer Policy: strict-origin-when-cross-origin
To let you test this better I posted an angular web app that simply call the rest.
Here you can read the code and here you can test it. Just remember to open the browser console to see the result.

Thank you for all you're doing to help me.

User avatar
oss
Site Admin
Posts: 5878
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: [NEW] REST search, JSON results

Sat Feb 23, 2019 7:20 pm

thanks for urls so I can test it.

It seems it is working now properly.

Show us then where it is implemented, it can be very useful for others too

pirasalbe
Posts: 9
Joined: Tue Feb 19, 2019 2:31 pm

Re: [NEW] REST search, JSON results

Sun Feb 24, 2019 2:53 pm

It is now working, thank you very much.
I'll implement rest call in my app and post here the source code of that part :D.

Return to “Developing”

Who is online

Users browsing this forum: No registered users and 29 guests