我正在使用 Spotify API 开发一个应用程序。我的问题是我正在尝试获取access_token但它不起作用。在文档中,它说我需要发送编码为 application/x-www-form-urlencoded 的正文,所以我搜索了一下,它应该只需设置request_body为字典即可工作。
这是我的函数的代码:
def get_access_token(self):
auth_code, code_verifier = self.get_auth_code()
endpoint = "https://accounts.spotify.com/api/token"
# as docs said data should be encoded as application/x-www-form-urlencoded
# as internet says i just need to send it as a dictionary. However it's not working
request_body = {
"client_id": f"{self.client_ID}",
"grant_type": "authorization_code",
"code": f"{auth_code}",
"redirect_uri": f"{self.redirect_uri}",
"code_verifier": f"{code_verifier}"
}
response = requests.post(endpoint, data=request_body)
print(response)
Run Code Online (Sandbox Code Playgroud)
我得到的回应始终是<Response [400]>
这里是文档,步骤 4 https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for- code-exchange-pkce
注意:我尝试将其作为curl执行,它工作正常,我不确定我在python代码中做错了什么,命令如下:
curl -d client_id={self.client_ID} -d grant_type=authorization_code -d …Run Code Online (Sandbox Code Playgroud) POST当使用正文中的 和其他参数发出请求时,许多服务可以接受 URL 中的查询字符串参数Content-Type: application/x-www-form-urlencoded,但 AWS API Gateway 似乎不能同时接受查询字符串参数。
POST当我使用映射模板和查询字符串 URL 参数(使用 Lambda 函数)调用 AWS API Gateway 时application/x-www-form-urlencoded,出现以下错误:
{
"message":"When Content-Type:application/x-www-form-urlencoded,
URL cannot include query-string parameters (after '?'):
'/prod/webhook?inputType=wootric&outputType=glip&url=...'"
}
Run Code Online (Sandbox Code Playgroud)
下面是一个 cURL 示例:
curl -XPOST 'https://{myid}.execute-api.{myregion}.amazonaws.com/prod/webhook? \
inputType=wootric&outputType=glip&url=https://hooks.glip.com/webhook/ \
11112222-3333-4444-5555-666677778888' \
-d "@docs/handlers/wootric/event-example_response-created.txt" \
-H 'Content-Type: application/x-www-form-urlencoded' -v
Run Code Online (Sandbox Code Playgroud)
具体目标是使用带有查询字符串参数的 URL 将 Wootric Webhook 事件发布到 Lambda 函数。
您可以在这里获取代码:
https://github.com/grokify/chathooks
Woodric 事件正文文件位于此处:
GitHub问题在这里:
https://github.com/grokify/chathooks/issues/15
错误消息似乎很明确,但我想问:
如果没有解决方案,除了部署像 Heroku 这样的托管服务器解决方案之外,是否还有一个好的轻量级解决方案。另外,其他云服务是否通过 API 网关 …
amazon-web-services query-string aws-api-gateway x-www-form-urlencoded
我正在尝试向POSTAPI发送请求以创建帐户。
请求运行良好,它应该是这样的:
还有 9 个标题是自动生成的,所以我没有显示它们,但如果您需要,我可以使用另一个屏幕。
我的请求是这样的:
import 'dart:convert' as convert ;
import 'package:my_project/requests/utils.dart';
import 'package:http/http.dart' as http;
Future<String> createUser(String firstName, String name, String mail,
String password, String confirmPassword, String birthDate,
String phone) async {
String url = BASE_URL + "createUser" ; // Don't worry about BASE_URL, the final url is correct
Map<String, dynamic> formMap = {
"name": name,
"surname": firstName,
"mail": mail,
"password": password,
"birth": birthDate,
"phone": phone,
"confirmPassword": confirmPassword
} ;
http.Response response = await …Run Code Online (Sandbox Code Playgroud) 我需要使用 x-www-form-urlencoded 主体创建剧作家 API 请求:来自邮递员的示例: 工作邮递员请求示例
我正在尝试这样做:
async getNewApiAccesToken({request})
{
const postResponse = await request.post("https://login.microsoftonline.com//token",{
ignoreHTTPSErrors: true,
FormData: {
'client_id': 'xyz',
'client_secret': 'xyz',
'grant_type': 'client_credentials',
'scope': 'api://xyz'
}
})
console.log(await postResponse.json());
return postResponse;Run Code Online (Sandbox Code Playgroud)
但它不起作用:/你能告诉我如何在剧作家中撰写这种请求吗?
javascript typescript x-www-form-urlencoded playwright playwright-test
我有一个API,其curl请求如下:
curl --request POST \
--url 'http://some.url/api/Resource/findByIds' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'data[ids][]=100025' \
--data 'data[ids][]=100028'
Run Code Online (Sandbox Code Playgroud)
如何在 OpenAPI (Swagger) 请求定义和示例(版本 3)中表示这一点?
这是我到目前为止所拥有的,但我似乎无法让示例正确显示。
api/Resource/findByIds:
post:
summary: Find resource by IDs
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
data:
type: object
properties:
ids:
type: array
description: IDs of resources to fetch
items:
type: integer
encoding:
data:
style: deepObject
explode: true
example:
data:
ids: [2334, 234, 20043]
Run Code Online (Sandbox Code Playgroud) 我从 api 接收 x-www-form-urlencoded 数据。
data = 'leads%5Bstatus%5D%5B0%5D%5Bid%5D=29078079'
Run Code Online (Sandbox Code Playgroud)
当我尝试将其转换为urllib.parse.parse_qs或urllib.parse.unquote
我得到一个类似的字典时
{
"leads[status][0][id]": [
"29078079"
]
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它转换为普通的 json 或 dict ?像这样
{
"leads": [
"id": "29078079"
]
}
Run Code Online (Sandbox Code Playgroud) 在 drf-spectaulous swagger 中,post 方法有以下 3 种内容类型
application/json
application/x-www-form-urlencoded
multipart/form-data
Run Code Online (Sandbox Code Playgroud)
无论如何,是否可以将“ application/x-www-form-urlencoded ”作为我的帖子方法的默认内容类型。
@extend_schema(
description='API authentication using email & password',
# OpenApiRequestBody('content': "application/x-www-form-urlencoded")
)
Run Code Online (Sandbox Code Playgroud)
在extend_schema函数中,尝试将内容类型添加为form-urlencoded。但没有运气。
提前致谢
django content-type django-rest-framework x-www-form-urlencoded drf-spectacular
问这个问题似乎有点奇怪,但我无法弄清楚。
我已经浏览过 stackoverflow 上的链接和谷歌,事实上尝试了很多东西,但我无法得到解决方案。下面是一些值得一提的
如何强制 Angular2 使用 x-www-form-urlencoded 进行 POST
问题 - api 的请求选项始终为 400(错误请求)
见解 -
下面是在另一个项目上运行的代码
const headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
});
const body = new HttpParams()
.set('grant_type', 'password')
.set('username', stateData.username)
.set('password', stateData.password)
.set('client_id', 'XXXXX-5B3C-4A7D-WEW-23BWWWF9B7872'); //Letters are dummy here for security reasons
//URL preceded by https
return this.http.post('abc.com/authtoken', body , {headers: headers }).pipe(
map(res => {
return res;
})
);
Run Code Online (Sandbox Code Playgroud)
现在,当我在另一个项目中尝试相同的代码时,它不会传递 OPTIONS 请求,抛出 400(错误请求)。
我们可以假设其余的事情都是为了使这项工作顺利进行。问题主要出在代码片段上。
最令人惊奇的是,当我在 url 中添加一个尾部斜杠(如 - authtoken/ …
我创建了一个 React 应用程序,从中调用基于 PHP 构建的服务器。
以下是我调用 PHP 文件的方式:
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: JSON.stringify({ name, username, password }),
};
console.log(requestOptions);
fetch('http://localhost/crud/requests/signup.php', requestOptions)
.then(res => res.json())
.then(data => console.log(data));
Run Code Online (Sandbox Code Playgroud)
这是我在 PHP 文件中的内容:
if (isset($_POST) && !empty($_POST)) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
当我打印$_POST变量时,我得到一个空数组。甚至$_RESPONSE是空的。
但是当我尝试像这样打印输入流时:
print_r(file_get_contents('php://input'));
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好。谁能解释为什么会发生这种情况?我尝试在文档中阅读它并查找一些论坛和博客,但对答案不满意。
django ×2
http-post ×2
javascript ×2
json ×2
python ×2
.net-core ×1
angular8 ×1
content-type ×1
dart ×1
flutter ×1
openapi ×1
php ×1
playwright ×1
post ×1
query-string ×1
spotify ×1
swagger ×1
typescript ×1