You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Spring OAuth2应用中用Postman请求OAuth2 Token?请修正我的请求

Got it, let's get your Postman request sorted out to match that curl command you're working with. I'll walk you through each step clearly so you can grab that access token successfully:

Fixing Your Postman Request for OAuth2 Client Credentials Flow

First, let's break down what your original curl command is doing under the hood:

$ curl acme:acmesecret@localhost:8080/oauth/token -d grant_type=client_credentials
  • It sends a POST request to localhost:8080/oauth/token
  • Uses Basic Authentication with username acme and password acmesecret
  • Passes form data (grant_type=client_credentials) as the request body

Here's how to replicate this exactly in Postman:

1. Set Up the Request Basics

  • Open Postman and create a new POST request
  • Paste the target URL into the address bar: http://localhost:8080/oauth/token

2. Configure Basic Authentication

  • Switch to the Authorization tab
  • From the "Type" dropdown menu, select Basic Auth
  • Enter acme in the Username field
  • Enter acmesecret in the Password field
    (Postman automatically encodes this pair into the Authorization header, just like the acme:acmesecret@ part of your curl command does)

3. Add the Form Data Body

  • Go to the Body tab
  • Select the form-data radio button
  • Add a single key-value pair:
    • Key: grant_type
    • Value: client_credentials

4. Send the Request

  • Click the Send button, and you should receive the access token response exactly as you would with the curl command.

If you still hit snags, double-check that your Spring Boot app is running on port 8080, and that the client credentials (acme/acmesecret) are properly configured in your app's OAuth2 settings.

内容的提问来源于stack exchange,提问作者gstackoverflow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:05:50