我正在尝试向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 --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'
任何帮助都可能为我节省数不清的时间来搜索谷歌如何完成这项工作的线索。
答案 0 :(得分: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})))