How can I convert the following CURL command to javascript fetch?
curl --request GET -L -c --url https://tableau.example.com/trusted/DjabukX7T3u_bTUT0z7NdQ==:rQS3WF-ol-5snlDTOYlQ7pS2/t/site/views/workbook_name/view_name
I used the above command on my server is working.
Then I throw this command to many online CURL to javascript fetch converters, and they all return only like this:
fetch('https://tableau.example.com/trusted/DjabukX7T3u_bTUT0z7NdQ==:rQS3WF-ol-5snlDTOYlQ7pS2/t/site/views/workbook_name/view_name');
The above fetch code is not working for me.
and it returns
Uncaught (in promise) TypeError: Failed to fetch.
I think the -c -L flag in CURL has the meaning for fetching:
https://curl.se/docs/manpage.html#-c
https://curl.se/docs/manpage.html#-L
What is the precise corresponding javascript fetch code for this CURL command?
thanks for the help from all of you.
CodePudding user response:
Most of the flags you are using for cURL are default behaviour for fetch
.
Since you are making a cross-origin request you need to set the credentials
flag to include
for cookies to be enabled.
Note that this will require the server to support a CORS preflight.