kaiyuanshe/open-hackathon

【对接测试服接口】发布新活动提交(带token)返回401错误

gakki88 opened this issue · 2 comments

Response (error)

error: {
  code: 401
  friendly_message: "The server could not verify that you are authorized to access the URL requested.  You either supplied the 
wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required."
  message: "login required"
}

cURL请求代码

curl "http://139.219.9.2:30150/api/admin/hackathon" ^
  -H "Connection: keep-alive" ^
  -H "Pragma: no-cache" ^
  -H "Cache-Control: no-cache" ^
  -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" ^
  -H "Authorization: token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InR5cGUiOiJ1c2VyIiwidXNlclBvb2xJZCI6IjVmMGU2MjhlNGJhNjA4ZTlhNjk1MzNhZSIsImFwcElkIjpudWxsLCJhcm4iOiJhcm46Y246YXV0aGluZzo1ZjBlNjI4ZTRiYTYwOGU5YTY5NTMzYWU6dXNlcjo1ZmJhODQzNWIyMjMyODM4MDAxYWMzOGIiLCJpZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsInVzZXJJZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsIl9pZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsInBob25lIjpudWxsLCJlbWFpbCI6bnVsbCwidXNlcm5hbWUiOiJnYWtraTg4IiwidW5pb25pZCI6IjI2NDgwMTE1Iiwib3BlbmlkIjoiMjY0ODAxMTUiLCJjbGllbnRJZCI6IjVmMGU2MjhlNGJhNjA4ZTlhNjk1MzNhZSJ9LCJpYXQiOjE2MDYyMzQ1OTksImV4cCI6MTYwNzUzMDU5OX0.xZnu2s7lgx05SY2j-W4Xf98-jDt7IFuNeQH0ZL0dRT4" ^
  -H "token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InR5cGUiOiJ1c2VyIiwidXNlclBvb2xJZCI6IjVmMGU2MjhlNGJhNjA4ZTlhNjk1MzNhZSIsImFwcElkIjpudWxsLCJhcm4iOiJhcm46Y246YXV0aGluZzo1ZjBlNjI4ZTRiYTYwOGU5YTY5NTMzYWU6dXNlcjo1ZmJhODQzNWIyMjMyODM4MDAxYWMzOGIiLCJpZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsInVzZXJJZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsIl9pZCI6IjVmYmE4NDM1YjIyMzI4MzgwMDFhYzM4YiIsInBob25lIjpudWxsLCJlbWFpbCI6bnVsbCwidXNlcm5hbWUiOiJnYWtraTg4IiwidW5pb25pZCI6IjI2NDgwMTE1Iiwib3BlbmlkIjoiMjY0ODAxMTUiLCJjbGllbnRJZCI6IjVmMGU2MjhlNGJhNjA4ZTlhNjk1MzNhZSJ9LCJpYXQiOjE2MDYyMzQ1OTksImV4cCI6MTYwNzUzMDU5OX0.xZnu2s7lgx05SY2j-W4Xf98-jDt7IFuNeQH0ZL0dRT4" ^
  -H "Content-Type: application/json" ^
  -H "Accept: */*" ^
  -H "Origin: http://localhost:1234" ^
  -H "Referer: http://localhost:1234/" ^
  -H "Accept-Language: en,zh-CN;q=0.9,zh;q=0.8,fr-FR;q=0.7,fr;q=0.6,en-US;q=0.5" ^
  --data-binary "^{^\^"name^\^":^\^"test111^\^",^\^"display_name^\^":^\^"ceshijiekou^\^",^\^"tags^\^":^\^"^\^",^\^"location^\^":^\^"^\^",^\^"registration_start_time^\^":^\^"2020-11-25T17:40^\^",^\^"registration_end_time^\^":^\^"2020-11-25T17:40^\^",^\^"event_start_time^\^":^\^"2020-11-25T17:40^\^",^\^"event_end_time^\^":^\^"2020-11-25T17:40^\^",^\^"judge_start_time^\^":^\^"2020-11-25T17:40^\^",^\^"judge_end_time^\^":^\^"2020-11-25T17:40^\^",^\^"ribbon^\^":^\^"^\^",^\^"headcount_limit^\^":^\^"^\^",^\^"short_description^\^":^\^"^\^",^\^"description^\^":^\^"^<p^>^<br^>^</p^>^\^",^\^"awards^\^":^[^],^\^"status^\^":0,^\^"stat^\^":^{^\^"register^\^":0,^\^"like^\^":0^}^}" ^
  --compressed ^
  --insecure

Headers截图

image
image
image

Hey # welcome to this repo. Thanks for submitting your first issue. We truely value it.

Solution:

Request Headers 中,去掉token header和Authorization里的’token ’前缀

Authorization: token_value

fixes #821