2016-03-04 43 views
1

我正在嘗試向api發出一個http請求,該請求會將某個給定的句子更改爲yoda可能會這麼說的方式。這裏是我的代碼,目前獲得包含一個錯誤「失蹤Mashape應用的關鍵。」:如何使用包含api密鑰的clj-http執行http請求?

(ns clojure-noob.core 
    (:gen-class) 
    (:require [clj-http.client :as client])) 

(defn api-request [method path body] 
    (:body 
    (client/request 
     {:basic-auth "*MY-AUTH-KEY-HERE*" 
     :method method 
     :url (str "https://yoda.p.mashape.com" path) 
     :content-type "text/plain" 
     :body body}))) 

(api-request :get "/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.++Oh+wait." "") 

:basic-auth部分是這個代碼中最可疑的部分。該API描述位於:https://market.mashape.com/ismaelc/yoda-speak 這是此API的工作捲曲的請求是什麼樣子:

curl --get --include 'https://yoda.p.mashape.com/yoda?sentence=You+will+learn+how+to+speak+like+me+someday.++Oh+wait.' \ 
    -H 'X-Mashape-Key: *MY-AUTH-KEY-HERE*' \ 
    -H 'Accept: text/plain' 

任何幫助可能我拯救無數多個小時刮谷歌對如何做到這一點的線索。

回答

3

看起來像關鍵需要在名爲X-Mashape-Key的特定標頭中使用,而不是使用HTTP基本身份驗證。

(client/request 
    {:headers {"X-Mashape-Key" "*MY-AUTH-KEY-HERE*"} 
    :method method 
    :url (str "https://yoda.p.mashape.com" path) 
    :content-type "text/plain" 
    :body body}))) 
+0

供其他人蔘考請關閉第二行打開的支架。 –

+0

我被抓住了!我發佈的代碼沒有運行它。我承認*恥辱*。 (現在修復) –