에서 POST 요청에서 다중 - PARAMS를 추출 할 수 없습니다 는 compojure
(defroutes upload-routes
(POST "/upload" {params :params} (println params))
나는
{}
을 얻었다.
그럼이 같은 시도 :
(defroutes upload-routes
(POST "/upload" {multipart-params :multipart-params} (println multipart-params))
나는 아직도 {}
을 얻었다.
내 미들웨어에 문제가있는 것 같습니다.
(ns cloudserver.handler
(:require [compojure.core :refer [defroutes routes]]
[compojure.route :as route]
[compojure.handler :as handler]
[cloudserver.routes.home :refer [home-routes]]
[noir.util.middleware :as noir-middleware]
[cloudserver.routes.auth :refer [auth-routes]]
[cloudserver.routes.upload :refer [upload-routes]]
[cloudserver.routes.search :refer [search-routes]]
[cloudserver.routes.download :refer [download-routes]]
[ring.middleware.defaults :refer [api-defaults wrap-defaults site-defaults]]
[ring.middleware.multipart-params :refer [wrap-multipart-params]]
[ring.middleware.params :refer [wrap-params]]
[noir.session :as session]
[ring.middleware.session.memory :refer [memory-store]]))
(def app
(->
(routes auth-routes
home-routes
upload-routes
search-routes
download-routes
app-routes)
session/wrap-noir-session
(wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false)
wrap-multipart-params
wrap-params))
(def app
(->
(routes auth-routes
home-routes
upload-routes
search-routes
download-routes
app-routes)
session/wrap-noir-session
(wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false)
wrap-multipart-params))
(def app
(->
(routes auth-routes
home-routes
upload-routes
search-routes
download-routes
app-routes)
session/wrap-noir-session
(wrap-defaults (-> site-defaults
(assoc-in [:security :anti-forgery] false)
(assoc-in [:params :multipart] true)
(assoc-in [:params :nested] true)))
handler/site))
(def app
(->
(routes auth-routes
home-routes
upload-routes
search-routes
download-routes
app-routes)
wrap-multipart-params
session/wrap-noir-session
(wrap-defaults(assoc-in site-defaults [:security :anti-forgery] false)))
(def app
(noir-middleware/app-handler
[auth-routes
home-routes
upload-routes
search-routes
download-routes
app-routes]
:ring-defaults (assoc site-defaults :security nil)))
하지만 내가 가진 유일한 결과는 {}
내 클라이언트 코드는 다음과 같습니다 :
그래서 나는 처리기를 변경하려고 여기 핸들러 나는 시도했다있다public int upload (String filename, String[] tags, String time, String fingerprint) throws IOException {
String url = host + "/upload";
CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
HttpPost httpPost = new HttpPost(url);
MultipartEntityBuilder mulentity = MultipartEntityBuilder.create();
mulentity.addBinaryBody("photo", new File(filename));
for (int i = 0; i < tags.length; i ++) {
mulentity.addTextBody("tag" + i, tags[i]);
}
mulentity.addTextBody("fingerprint", fingerprint);
mulentity.addTextBody("time", time);
mulentity.addTextBody("filename", filename.substring(filename.lastIndexOf(File.separatorChar) + 1, filename.length()));
HttpEntity entity = mulentity.build();
httpPost.setEntity(entity);
httpPost.setHeader("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);
int status = 3;
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpClient.execute(httpPost, responseHandler);
status = Integer.parseInt(response);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
httpClient.close();
}
return status;
}
나는 정말로 clojure 웹 프로그래밍의 녹색 손이다. 고마워요!
문제가 해결되었습니다. 요청의 경계가 잘못 되었기 때문입니다.
요청 헤더의 경계가 요청 본문의 경계와 다르다는 것이 문제입니다. 아직도 고마워. – Arturo