Page 3 of 7

Re: [NEW] REST search, JSON results

Posted: Mon Jan 07, 2019 11:38 am
by oss
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.

Re: [NEW] REST search, JSON results

Posted: Tue Feb 19, 2019 2:35 pm
by pirasalbe
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

Re: [NEW] REST search, JSON results

Posted: Tue Feb 19, 2019 7:35 pm
by oss
Hi

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

Re: [NEW] REST search, JSON results

Posted: Tue Feb 19, 2019 10:04 pm
by pirasalbe
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??

Re: [NEW] REST search, JSON results

Posted: Wed Feb 20, 2019 3:50 am
by oss
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

Re: [NEW] REST search, JSON results

Posted: Wed Feb 20, 2019 2:27 pm
by pirasalbe
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?

Re: [NEW] REST search, JSON results

Posted: Wed Feb 20, 2019 5:53 pm
by oss
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

Re: [NEW] REST search, JSON results

Posted: Wed Feb 20, 2019 8:24 pm
by pirasalbe
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.

Re: [NEW] REST search, JSON results

Posted: Thu Feb 21, 2019 2:22 am
by oss
ok let us know if it works, and if it doesnt what need to be changed - I assume it is header thing.

Re: [NEW] REST search, JSON results

Posted: Thu Feb 21, 2019 10:02 am
by pirasalbe
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");
.

Re: [NEW] REST search, JSON results

Posted: Fri Feb 22, 2019 3:42 am
by oss
Hi

ok, will check, thanks for debug.

Re: [NEW] REST search, JSON results

Posted: Sat Feb 23, 2019 5:41 am
by oss
ok I applied quick fix, can you check now ?

Re: [NEW] REST search, JSON results

Posted: Sat Feb 23, 2019 12:34 pm
by pirasalbe
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.

Re: [NEW] REST search, JSON results

Posted: Sat Feb 23, 2019 7:20 pm
by oss
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

Re: [NEW] REST search, JSON results

Posted: Sun Feb 24, 2019 2:53 pm
by pirasalbe
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.