405 POST 方法不允许(澄清)
405 POST method not allowed (clarifai)
我正在尝试在我的 React 应用程序上使用澄清人脸检测 api,但我一直收到错误 POST:不允许使用 405 方法 我已经尝试在堆栈溢出时通过一些解决方案,但是似乎我正在使用更新版本的 clarifai api 请求方法并且与我遇到的解决方案不一致有人可以帮助我解决这个问题
下面是app.js代码
import NavBar from "../components/navbar/NavBar";
import ImageLinkFrom from "../components/imagelinkform/ImageLinkFrom";
import ImageRecognition from "../components/imagerecognition/Imagerecognition";
import Logo from "../components/logo/Logo";
import "./App.css";
import Rank from "../components/rank/Rank";
import { useState } from "react";
import Clarifai from "clarifai";
function App() {
const [input, setInput] = useState("");
const [imageurl, setImageurl] = useState("");
const onInputChange = (e) => {
setInput(e.target.value);
};
const onButtonSubmit = () => {
setImageurl(input);
const USER_ID = "myUserId";
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = "myPAT";
const APP_ID = "myAppId";
const MODEL_ID = "color-recognition";
// const MODEL_VERSION_ID = "45fb9a671625463fa646c3523a3087d5";
// Change this to whatever image URL you want to process
const IMAGE_URL = "https://samples.clarifai.com/metro-north.jpg";
const raw = JSON.stringify({
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
inputs: [
{
data: {
image: {
base64: IMAGE_URL,
},
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
debugger;
fetch(
"https://api.clarifai.com/v2/models/" +
MODEL_ID +
"/versions/" +
"/outputs",
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
};
return (
<div className="App">
<NavBar />
<Logo />
<Rank />
<ImageLinkFrom
onInputChange={onInputChange}
onButtonSubmit={onButtonSubmit}
/>
<ImageRecognition imageurl={imageurl} />
</div>
);
}
export default App;
用户、应用程序和版本 ID 需要转到 url。
从请求正文中删除此部分:
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
更改路径:
fetch(
"https://api.clarifai.com/v2/users/"+
USER_ID +
"/apps/" +
APP_ID +
"/models/" +
MODEL_ID +
"/versions/" +
MODEL_VERSION_ID +
"/outputs",
requestOptions
)
或无版本(默认使用最新版本)
fetch(
"https://api.clarifai.com/v2/users/"+
USER_ID +
"/apps/" +
APP_ID +
"/models/" +
MODEL_ID +
"/outputs",
requestOptions
)
我正在尝试在我的 React 应用程序上使用澄清人脸检测 api,但我一直收到错误 POST:不允许使用 405 方法 我已经尝试在堆栈溢出时通过一些解决方案,但是似乎我正在使用更新版本的 clarifai api 请求方法并且与我遇到的解决方案不一致有人可以帮助我解决这个问题
下面是app.js代码
import NavBar from "../components/navbar/NavBar";
import ImageLinkFrom from "../components/imagelinkform/ImageLinkFrom";
import ImageRecognition from "../components/imagerecognition/Imagerecognition";
import Logo from "../components/logo/Logo";
import "./App.css";
import Rank from "../components/rank/Rank";
import { useState } from "react";
import Clarifai from "clarifai";
function App() {
const [input, setInput] = useState("");
const [imageurl, setImageurl] = useState("");
const onInputChange = (e) => {
setInput(e.target.value);
};
const onButtonSubmit = () => {
setImageurl(input);
const USER_ID = "myUserId";
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = "myPAT";
const APP_ID = "myAppId";
const MODEL_ID = "color-recognition";
// const MODEL_VERSION_ID = "45fb9a671625463fa646c3523a3087d5";
// Change this to whatever image URL you want to process
const IMAGE_URL = "https://samples.clarifai.com/metro-north.jpg";
const raw = JSON.stringify({
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
inputs: [
{
data: {
image: {
base64: IMAGE_URL,
},
},
},
],
});
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
Authorization: "Key " + PAT,
},
body: raw,
};
debugger;
fetch(
"https://api.clarifai.com/v2/models/" +
MODEL_ID +
"/versions/" +
"/outputs",
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
};
return (
<div className="App">
<NavBar />
<Logo />
<Rank />
<ImageLinkFrom
onInputChange={onInputChange}
onButtonSubmit={onButtonSubmit}
/>
<ImageRecognition imageurl={imageurl} />
</div>
);
}
export default App;
用户、应用程序和版本 ID 需要转到 url。
从请求正文中删除此部分:
user_app_id: {
user_id: USER_ID,
app_id: APP_ID,
},
更改路径:
fetch(
"https://api.clarifai.com/v2/users/"+
USER_ID +
"/apps/" +
APP_ID +
"/models/" +
MODEL_ID +
"/versions/" +
MODEL_VERSION_ID +
"/outputs",
requestOptions
)
或无版本(默认使用最新版本)
fetch(
"https://api.clarifai.com/v2/users/"+
USER_ID +
"/apps/" +
APP_ID +
"/models/" +
MODEL_ID +
"/outputs",
requestOptions
)