1

我正在尝试向 api 发出 http 请求,将给定的句子更改为 yoda 可能会说的方式。这是我的代码,当前出现包含“缺少 Mashape 应用程序密钥”的错误:

(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 请求的样子:

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'

任何帮助都可能为我节省无数时间,让我在谷歌上寻找有关如何完成此操作的线索。

4

1 回答 1

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})))
于 2016-03-04T22:18:44.400 回答