Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求Anki报403Forbidden #28

Open
Sunosay opened this issue Apr 14, 2024 · 2 comments
Open

请求Anki报403Forbidden #28

Sunosay opened this issue Apr 14, 2024 · 2 comments

Comments

@Sunosay
Copy link

Sunosay commented Apr 14, 2024

在页面上点击按钮,就会提示 添加失败:AxiosError: Request failed with status code 403
我把请求直接复制出来在postman里试了试,发现header有个Origin:http://localhost:8081,去了就能调用成功了.

F12的curl

curl 'http://localhost:8080/ankiconnect' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Origin: http://localhost:8080' \
  -H 'Referer: http://localhost:8080/dict' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0' \
  -H 'sec-ch-ua: "Microsoft Edge";v="123", "Not:A-Brand";v="8", "Chromium";v="123", "Microsoft Edge WebView2";v="123"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw '{"action":"addNote","version":6,"params":{"note":{"deckName":"test","modelName":"ja-learner","fields":{"单词":"差し引く | さしひく ③","例句":"扣","解释":"<li><b>扣除,减去</b>(ある数量から他の数量を引きさる。さっぴく。)</li>"},"options":{"allowDuplicate":false,"duplicateScope":"deck","duplicateScopeOptions":{"checkChildren":false,"checkAllModels":false}}}}}'

anki connect 配置文件

{
    "apiKey": null,
    "apiLogPath": null,
    "ignoreOriginList": [],
    "webBindAddress": "127.0.0.1",
    "webBindPort": 8765,
    "webCorsOriginList": [
        "http://localhost"
    ]
}

appsettings.json

"Anki": {
			"AnkiConnectUrl": "http://127.0.0.1:8765",
			"Deck": "test",
			"Model": "ja-learner",		
			"FieldNames":{
				"Word": "单词",
				"Example": "例句",
				"Explain": "解释"
			}
		}

大佬方便让我看一下你的配置吗

@ks233
Copy link
Owner

ks233 commented Apr 15, 2024

感谢反馈!我看了下我的配置,唯一的区别是

"webCorsOriginList": [
    "*"
]

你改一下试试?

@Sunosay
Copy link
Author

Sunosay commented Apr 15, 2024

感谢反馈!我看了下我的配置,唯一的区别是

"webCorsOriginList": [
    "*"
]

你改一下试试?

非常感谢!解决了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants