?文章來源地址http://www.zghlxwxcb.cn/news/detail-636827.html
這個(gè)錯(cuò)誤提示?Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
?表明服務(wù)器不支持接收?application/x-www-form-urlencoded
?類型的數(shù)據(jù)。
如果你的服務(wù)器端代碼是使用Spring框架編寫的,你可以嘗試改為接收?application/json
?類型的數(shù)據(jù)。
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class YourController {
@PostMapping("/your-endpoint")
public String handlePostRequest(@RequestBody YourDataClass data) {
// 處理請(qǐng)求的代碼
// 使用 @RequestBody 注解將請(qǐng)求體的 JSON 數(shù)據(jù)映射到 YourDataClass 對(duì)象
// 返回響應(yīng)數(shù)據(jù)
return "Success";
}
}
在上面的示例中,YourController
?是一個(gè)Spring控制器,使用?@PostMapping
?注解指定了處理POST請(qǐng)求的方法。
handlePostRequest
?方法使用?@RequestBody
?注解將請(qǐng)求體的 JSON 數(shù)據(jù)映射到?YourDataClass
?對(duì)象中。你需要根據(jù)實(shí)際情況創(chuàng)建一個(gè)對(duì)應(yīng)的類來存儲(chǔ)請(qǐng)求數(shù)據(jù)。
另外,請(qǐng)確保你的請(qǐng)求頭中指定了正確的?Content-Type
?為?application/json
,例如:
axios.post(url, jsonData, {
headers: {
'Content-Type': 'application/json'
}
})
?文章來源:http://www.zghlxwxcb.cn/news/detail-636827.html
?
到了這里,關(guān)于Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘a(chǎn)pplication/x-ww的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!