Request parameters are not processed in the Ring / Compojure application

I am writing a web application using Ring and Compojure and the Friend library for authorization. I recently made some changes to the project, and now I can no longer request query parameters.

What I did was:

; Routes definition
(defroutes app-routes
  (POST "/*.do" request 
    (insert-data (:params request))))

; Middlewares
(def secured-routes
  (handler/site
    (-> app-routes
        wrap-params
        (friend/authenticate friend-params-map))))
Parameters

and the form / URL will be parsed onto a Clojure map. Now it does not work, and (:params request)contains form cards

{:* <request-url>}

using one key :*. If I try (println request), get a Clojure card with a lot of key-value pairs, among which are

:body #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x6ef9a9e1 HttpInputOverHTTP@6ef9a9e1]

which seem to contain request data, right? But how do I get them?

I used to just use middleware wrap-paramsas described above and it worked.

, , (body-string request) , . Clojure URL. , - .

- ? , , , wrap-params .

!

: @nberger, secured-routes :

(def secured-routes
  (-> app-routes
      (wrap-defaults site-defaults)
      (friend/authenticate friend-params-map)))

( ). wrap-defaults friend/authenticate, , - (???)

+4
1

. POST to *.do application/json content-type. jQuery ajax, :

$.ajax({ 
  url: '/saveInput.do',
  type: 'POST',
  contentType: 'application/json; charset=UTF-8',
  data: JSON.stringify(formValues),
});

$.ajax({ 
  url: '/saveInput.do',
  type: 'POST',
  data: formValues,
});

. , Ajax JSON wrap-json-params ring-json, :

(def secured-routes
  (-> app-routes
      (friend/authenticate friend-params-map)
      (wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
      wrap-json-params))

. @nberger - !

+2

Source: https://habr.com/ru/post/1598723/


All Articles