Friday, May 17, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 934  / 2 Years ago, tue, june 7, 2022, 6:45:57

When I enter the command:



$curl -basic https://www.google.com$


The output I receive is simply the text for the html page that we see when we visit the website.



but when I execute:



$curl -basic https://www.yahoo.com$


I receive no output, and the domain in my terminal changes from username@computer_name to Regional Redirectusername@computername.



What does this mean? I'm just not comfortable with that seeing I had thought what I was doing was sending a request to receive the text based content on the index page for a www domain. I apologize if this question is too vague, but I'd definitely like to know what the difference is here.



Thanks in advance


More From » command-line

 Answers
7

If You need always get HTML result I recommend use using curl flag "-L":



curl -L yahoo.com


or



curl -L https://www.yahoo.com


This flag force curl follow all URL redirects (graphical browser behavior). In case when site will redirect you couple of times, for example, to regional version, you always have chance get final HTML.



From curl man:



-L, --location




(HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a
3XX
response code), this option will make curl redo the request on the new place. If used together with -i, --include or -I,
--head,
headers from all requested pages will be shown. When authentication is used, curl only sends its credentials to the initial
host. If
a redirect takes curl to a different host, it won't be able to intercept the user+password. See also --location-trusted on
how to
change this. You can limit the amount of redirects to follow by using the --max-redirs option.



When curl follows a redirect and the request is not a plain GET (for example POST or PUT), it will do the following request
with a
GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following
request
using the same unmodified method.



You can tell curl to not change the non-GET request method to GET after a 30x response by using the dedicated options
for that:
--post301, --post302 and --post303.



[#6142] Thursday, June 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diket

Total Points: 167
Total Questions: 124
Total Answers: 109

Location: Somalia
Member since Wed, Mar 15, 2023
1 Year ago
;