标签: x-www-form-urlencoded

PYTHON:requests.post() 如何发送编码为 application/x-www-form-urlencoded 的 request_body

我正在使用 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)

python post spotify python-requests x-www-form-urlencoded

10
推荐指数
1
解决办法
2万
查看次数

AWS API Gateway 是否可以支持带有正文和查询字符串参数的“application/x-www-form-urlencoded”?

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 事件正文文件位于此处:

https://raw.githubusercontent.com/grokify/chathooks/master/docs/handlers/wootric/event-example_response-created.txt

GitHub问题在这里:

https://github.com/grokify/chathooks/issues/15

错误消息似乎很明确,但我想问:

  1. 是否有解决方法来配置 API 网关以支持两者?
  2. AWS 是否有基于标准的原因不支持此功能,或者这只是一个设计决策/限制?

如果没有解决方案,除了部署像 Heroku 这样的托管服务器解决方案之外,是否还有一个好的轻量级解决方案。另外,其他云服务是否通过 API 网关 …

amazon-web-services query-string aws-api-gateway x-www-form-urlencoded

8
推荐指数
1
解决办法
1万
查看次数

如何在 Flutter 中发布 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)

http-post dart flutter x-www-form-urlencoded

6
推荐指数
3
解决办法
5757
查看次数

TS/playwright - 如何使用 x-www-form-urlencoded 正文发布 api 请求?

我需要使用 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

6
推荐指数
1
解决办法
2687
查看次数

如何在 .NET Core 3.1 或 .NET Standard 中反序列化 x-www-form-urlencoded 编码字符串?

如何在 .NET Core 3.1 或 .NET Standard (C#) 中反序列化 x-www-form-urlencoded 编码字符串?

我知道这个问题-答案。但是,FormDataCollection 在 .NET Core 3.1 中似乎不可用。 看这里

编辑:我正在由另一个外部系统将此编码数据传回。我不是在编写 ASP.NET Core 网站/API。

serialization .net-core x-www-form-urlencoded

5
推荐指数
1
解决办法
4498
查看次数

如何使用数组为 application/x-www-form-urlencoded 请求定义 Swagger

我有一个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)

swagger openapi x-www-form-urlencoded

5
推荐指数
0
解决办法
1962
查看次数

如何使用 Python (Django) 将 x-www-form-urlencoded 转换为 json

我从 api 接收 x-www-form-urlencoded 数据。

data = 'leads%5Bstatus%5D%5B0%5D%5Bid%5D=29078079'
Run Code Online (Sandbox Code Playgroud)

当我尝试将其转换为urllib.parse.parse_qsurllib.parse.unquote 我得到一个类似的字典时

{
    "leads[status][0][id]": [
        "29078079"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能将它转换为普通的 json 或 dict ?像这样

{
    "leads": [
       "id": "29078079"
    ]
}
Run Code Online (Sandbox Code Playgroud)

python django json x-www-form-urlencoded

5
推荐指数
1
解决办法
2368
查看次数

drf-spectaulous 将请求内容类型定义为“application/x-www-form-urlencoded”

在 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

5
推荐指数
0
解决办法
559
查看次数

Angular 8 Http POST,内容类型为 application/x-www-form-urlencoded

问这个问题似乎有点奇怪,但我无法弄清楚。

我已经浏览过 stackoverflow 上的链接和谷歌,事实上尝试了很多东西,但我无法得到解决方案。下面是一些值得一提的

Angular 6 HTTP 客户端发布 - 错误请求

如何强制 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/ …

http-post angular8 x-www-form-urlencoded

2
推荐指数
1
解决办法
7245
查看次数

无法从 $_POST 变量访问使用 JSON.stringify 序列化的表单数据

我创建了一个 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)

一切似乎都很好。谁能解释为什么会发生这种情况?我尝试在文档中阅读它并查找一些论坛和博客,但对答案不满意。

javascript php json x-www-form-urlencoded

2
推荐指数
1
解决办法
431
查看次数