第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Angular 調(diào)用 java web API 中為 http.post 傳遞參數(shù)

在 Angular 調(diào)用 java web API 中為 http.post 傳遞參數(shù)

桃花長(zhǎng)相依 2021-09-15 16:52:10
我有一個(gè)奇怪的情況,可能是因?yàn)槲义e(cuò)過(guò)了一些我沒(méi)有意識(shí)到或不知道的事情。我正在使用 Angular 創(chuàng)建一個(gè)簡(jiǎn)單的登錄 UI,并調(diào)用在 java 中創(chuàng)建的 Web API。java web API函數(shù)如下@RequestMapping(value = "/logon", method = RequestMethod.POST, produces = {"application/json"})@ResponseBodypublic String logon(        @RequestParam(value = "userID", required = true) String userID,        @RequestParam(value = "password", required = true) String password,        HttpServletRequest request)現(xiàn)在,如果我使用 http.post 如下login(username: string, password: string) {    return this.http.post(this.url+"/security/logon/",                           JSON.stringify({ userID: username, password: password }) )然后我在 Google Chrome 瀏覽器中收到以下錯(cuò)誤:POST http://localhost:8080/logon/ 400 (Required String parameter 'userID' is not present)但是,如果我將代碼更改如下:login(username: string, password: string) {    var usrpwd = "userID=" + username + "&password=" + password;    return this.http.post(this.url+"/security/logon?"+usrpwd, usrpwd )它完美地工作。我錯(cuò)過(guò)了什么嗎?為什么應(yīng)該是傳遞的參數(shù)的 http.post 的第二個(gè)參數(shù)似乎不起作用?提前感謝您的任何回復(fù)或反饋。
查看完整描述

2 回答

?
千巷貓影

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

您正在使用兩個(gè)必需參數(shù)定義端點(diǎn) url,并且此類(lèi)參數(shù)必須在 url 中(請(qǐng)在此處查看),因此當(dāng)您向端點(diǎn)發(fā)出請(qǐng)求時(shí),該 url 必須為:

http://localhost:8080/logon?userID=yourUserId&password=yourUserPassword

在第一個(gè)實(shí)現(xiàn)中,您沒(méi)有向 url 添加查詢參數(shù),因此向 url http://localhost:8080/logon/發(fā)出請(qǐng)求,因?yàn)樗鼪](méi)有所需的參數(shù),您的 web 層返回400 http code,這意味著一個(gè)錯(cuò)誤的請(qǐng)求(因?yàn)樵俅?,您?url 不包含所需的參數(shù))。


查看完整回答
反對(duì) 回復(fù) 2021-09-15
  • 2 回答
  • 0 關(guān)注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)