[英]Clojure GET request of ShipStation using clj-http.client
我正在嘗試使用來自 ShipStation 的 clj-http.client 使用 GET 請求並收到 401 錯誤,
他們有很多不同語言的例子來說明如何做到這一點。 Javascript 看起來很簡單:
var myHeaders = new Headers();
myHeaders.append("Host", "ssapi.shipstation.com");
myHeaders.append("Authorization", "username:password");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://ssapi.shipstation.com/orders/orderId", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
這是我的 clojure 客戶端/獲取代碼,它在沒有標頭和使用 {:async? true} 來自其他網站,例如 jsonplaceholder:
(client/get "https://ssapi.shipstation.com/shipments?shipDateStart=2023-01-05&shipDateEnd=2023-01-05"
{:header { "Host" "ssapi.shipstation.com" "Authorization" "username:password"}}
(fn [response] (println "hello" (get response :body)))
(fn [exception] (println "exception message is: " (.getMessage exception))))
有人可以幫我解決這個 GET 請求的格式嗎?
在 clj-http 中找到了調用 shipstation api 的答案: https://stackoverflow.com/a/25794180/21046503
(clj-http.client/get "http://my.domain.com"
{:basic-auth [username password]})
根據文檔,它看起來像你想要的:
(client/get "https://ssapi.shipstation.com/shipments"
{:async? true
:basic-auth "username:password"
:query-params {:shipDateStart "2023-01-05" :shipDateEnd "2023-01-05"
:as :json}
(fn [response] (println "hello" (get response :body)))
(fn [exception] (println "exception message is: " (.getMessage exception))))
這假設 Basic-Auth 正在發揮作用,這是端點和 api 文檔所建議的,但我不是 shistation 用戶
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.