Generate Robust C# Code
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- csharp, typescript
调研方向
从 C# 代码片段生成入口开始,将当前的 form-urlencoded 输出与 issue 中的两个示例进行比较,重点关注参数名称和值的表示方式。完成的标准是:生成的 C# 使用带有运行时安全 URL 编码的请求参数,而不是嵌入一个经过编码的请求体字符串。
由索引模型根据 Issue 内容生成。
描述
Improvement Suggestion:
I would have liked the following autogenerated C# for a HTTP POST request with the single parameter err of value + & serialized as x-www-form-urlencoded in the body.
var client = new RestClient("https://localhost");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "da4d0044-61a9-3943-40db-9e753aca6020");
request.AddHeader("cache-control", "no-cache");
Action<string,string> parameter = (name, value) => request.AddParameter(name, value);
parameter("err", "+ &");
IRestResponse response = client.Execute(request);
but what Postman did produce for me was the following C# code:
var client = new RestClient("https://localhost");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "da4d0044-61a9-3943-40db-9e753aca6020");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "err=%2B%20%26", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Rationale
parameter("err", "+ &");is more readable than "[..]err=%2B%20%26[..]". The value,+ &, is more recognizable.- The code is more maintanable. At work, I tried the following development workflow:
(a) Type a minimal working example request into to Postman.
(b) Generate C# code.
(c) Copy generated code to Visual Studio.
(d) Replace example values by C# method parameters.
This workflow failed, because the method parameters were not x-www-form-urlencoded at runtime. Generating UrlEncode() calls would make writing a consumer of a HTTP POST x-www-form-urlencoded API effortless. - This usage of
IRestRequest.AddParameteris encouraged, whereas the currently generated code depends on an internal hack not meant for 3rd party usage.
/// - RequestBody: Used by AddBody() (not recommended to use directly)
App Details:
Postman for Windows
Version 5.3.2
win32 6.1.7601 / x64
Continuation of: https://github.com/postmanlabs/postman-app-support/issues/3870
- 主要语言
- TypeScript
- 星标
- 1.2k
- 派生
- 242
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Kong/httpsnippet 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 62/100
Kong/httpsnippet#356 ·
-
难度 3/5 1-2 天 新手友好度 35/100
Kong/httpsnippet#389 ·
-
难度 5/5 一周以上 新手友好度 25/100
Kong/httpsnippet#383 ·
-
难度 3/5 1-2 天 新手友好度 35/100
Kong/httpsnippet#379 ·
-
难度 3/5 1-2 天 新手友好度 48/100
Kong/httpsnippet#370 ·
相似的 Issue
-
comp/desktop P3 type/bug
难度 1/5 1 小时以内 新手友好度 92/100
NousResearch/hermes-agent#118866 ·
-
Browser Waiting for: Product Owner
难度 2/5 1-3 小时 新手友好度 85/100
getsentry/sentry-javascript#24577 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
agilepathway/label-checker#640 ·
-
Plugin stuck at "loading" on DSH 0.1.6-alpha.2 — turnTail list slot registration missing options.id 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 68/100
chrisparsons83/flexspotff#153 ·