tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

"--location(-L)" and "--request(-X) POST" makes all request as POST after redirection, #210

Closed hwiorn closed 2 years ago

hwiorn commented 2 years ago

I found this issue after I got a 404 response.

The issue is related to this stackoverflow Q&A

If -L and -X <HTTP-method> are used, curl redirects all request as specified <HTTP-method> instead of following HTTP response(e.g. Moved 30x).

My request code is

(setq login-url "https://COOLSITE.co.kr/users/login")
(require 'request)
(setq csrf-token "cifvHPBvReuhKbobyd9BJq3_SPF99Oc0FSXsERXi4_T4YcXd1B3SPTKPYx4B-IuLbrA7A0iYgoM3e6WEBBClwg")
(setq user-email "hwiorn@gmail.com")
(setq user-password "OMITTED")
(request login-url
  :type "POST"
  :data `(("authenticity_token" . ,csrf-token)
          ("user[email]" . ,user-email)
          ("user[password]" . ,user-password)
          ("button" . ""))
  :encoding 'utf-8
  :headers `(("Referer" . ,login-url)
             ("User-Agent" . "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36")
             ("Accept" . "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
             )
  :sync t
  :complete (cl-function
            (lambda (&key response &allow-other-keys)
              (message "%s" (pp-to-string response))
            )))

And the curl execution which is generated by emacs-request is

echo 'authenticity_token=cifvHPBvReuhKbobyd9BJq3_SPF99Oc0FSXsERXi4_T4YcXd1B3SPTKPYx4B-IuLbrA7A0iYgoM3e6WEBBClwg&user%5Bemail%5D=hwiorn%40gmail.com&user%5Bpassword%5D=OMITTED&button=' |\
curl -vvvv --location --cookie /home/gglee/.emacs.d/.local/cache/request/curl-cookie-jar \
    --cookie-jar /home/gglee/.emacs.d/.local/cache/request/curl-cookie-jar \
    --include \
    --write-out test.out \
    --compressed \
    --request POST \
    --header 'Referer: https://COOLSITE.co.kr/users/login' \
    --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
    --url 'https://COOLSITE.co.kr/users/login' \
    --data-binary @-
hwiorn commented 2 years ago

Never mind.

I removed :type "POST" line. and It works now.