Error 301 with HTTP()
#1

Hello, I've got a problem with the function HTTP. I'm trying to get some information to a website with SSL.
Website: https://samples.openweathermap.org/data/2.5/weather

When I paste this URL into my browser, it work perfectly. But for the script, it return me an error:

Code:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty/1.9.7.1</center>
</body>
</html>
PHP Code:
    format(stringsizeof(string), "%s?id=%d&appid=%s"API_URLCITY_CODEAPI_KEY);
    
printf("string: %s"string);
    
HTTP(-1HTTP_GETstring"""weather_response"); 
Thank's you
Reply
#2

Well, i am not sure, but that site requests n api key.

I get an error, when i want to open it in the browser.
Reply
#3

The native sa-mp http() function is only a basic HTTP 1.0 and does not seems support SSL, your browser (which must be modern already) supports HTTP 2.0 and comes with ssl client and certificates thats why it works...

So please make sure first the site you are accessing complies with the requirement of samp http client... Fortunately there is a plugin for this which you can find in this forum

(Sry posting from phone)
Reply
#4

Quote:
Originally Posted by RoboN1X
View Post
The native sa-mp http() function is only a basic HTTP 1.0 and does not seems support SSL, your browser (which must be modern already) supports HTTP 2.0 and comes with ssl client and certificates thats why it works...

So please make sure first the site you are accessing complies with the requirement of samp http client... Fortunately there is a plugin for this which you can find in this forum

(Sry posting from phone)
I think you have reason. Did you know a plugin to perform this ?
Reply
#5

Quote:
Originally Posted by djoudjou
View Post
I think you have reason. Did you know a plugin to perform this ?
There are some, I have never tried but i think when you want to do with API this can help:
https://sampforum.blast.hk/showthread.php?tid=653362

Quote:
Originally Posted by Y_Less
View Post
Did any of you bother to look up what 301 means? Or even just read the error given in the response in the first post.

301 is "Mover Permanently". That means the data is somewhere else. It works in your browser because the browser sees 301 and goes to the new location. It doesn't work in your code because you don't.
I did, in the past i was trying to achieve similarly what the thread starter did (just different site)
It just that i am not sure wether the response was actually a "301" http code (he didnt mention it) or it can be a success http code with response body "moved permanently" (as he posted the html docs code) where some common webserver response to redirect a browser from http to https (if im not wrong)
It is just that i have no idea what the openweathermap site provides with its API (confirm it with the official guide) nor what openresty web server does.. Somewhat i'd expected a new address for redirect in the response, but i didnt really think/hope much as it wasnt 303.

Nevertheless, if it has something to do with API i dont think it was enough to perform without some include/plugin libraries
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)