Comments (5)
Cookie只支持单字节字符,格式为{key}={value},等号是关键字,如果{key}或{value}包含等号,应该在应用层处理。你的代码想处理等号,但没有考虑{key}包含等号的情况。
from webapiclient.
我的代码是按照浏览器默认情况去写的,并且也只是保证了基本正确而已,因为Cookie有很多特殊情况我的代码并没有处理。浏览器的默认设置是把第一个=当作分割符,所以在实践上应该是不会有人在Name里面加入=的。就标准来说,并没有规定什么关键字,而且=号并不特别,反而是逗号,分号,空格是不允许出现的。
这里参考的标准是NetSpace发布的Spec Spec
当然后面有更为严格的标准出现,那就是RFC6265,它规定了Name只能包含 !#$%&'*+-.^_|~ 这些其他字符,Value只能包含 !#$%&'()*+-./:<=>?@[]^_
{|}~ 这些其他字符。
这里参考的标准是RFC 6265 第4.1.1节,里面引用的是RFC 2616的2.2节。
所以我觉得这个代码应该是满足我自己描述的需求的。
from webapiclient.
增加了一个代码提交,类似PHP的SetCookie和SetRawCookie两个Api,HeaderAttribute增加EncodeCookie属性用于选择使用SetCookie或SetRawCookie,默认为true;两个Api都调用HttpUtility的IEnumerable ParseCookie(string cookieValues, bool useUrlEncode)方法。
from webapiclient.
对了,我上面说这里还有很多特殊情况,我也一个个列出来,你看看你要不要去处理(这里指的是浏览器的一些行为,其实都是因为标准写的太烂,所以才那么多诡异的东西)。
1.Name或Value是空字符串应该也是可以被接受的。
2.不包含=的语句当作Name为空,比如value等价于=value。
3.控制字符不被允许。
4.允许出现空格和逗号之类的只要不是在value的前后就可以。
好像大概就这些吧,你可以考虑一下。
from webapiclient.
.net的Cookie类内部也做了验证处理,其实现为不支持空的name,value前后可以为空格。
from webapiclient.
Related Issues (20)
- 是否支持失败重试+自定义重试策略 HOT 5
- 是否考虑支持接口转发的功能 HOT 5
- .net 7.0 Console程序怎么使用该组件? HOT 2
- .net 7.0的Console程序提示不支持将ContentType为 text/html 的内容转换为对象 HOT 3
- 生成上传文件代理时,找不到FileParameter参数。
- 参数为实体类时是否有Attribute可用于自定义字段名 HOT 4
- TimeOut action属性和Param属性 设置之后都不起作用 无论设置多少都是60秒超时 HOT 2
- WriteLog方法BUG。 HOT 2
- 如何处理超时异常 HOT 2
- 请问 HttpApiClient.Create<T>() 还支持吗? HOT 1
- 请求执行时出现SocketException,是否考虑将HttpContext也抛出
- 支持添加自定义请求头吗? HOT 5
- HttpRequestException.StatusCode 错误 HOT 3
- 重写IsUnauthorizedAsync读取Body判断Status HOT 4
- CancellationTokenTypeAttribute类变量用错了
- 如何在ApiReturnAttribute进行重发? HOT 2
- 偶尔抛出异常,原因不明,抛出异常的位置:JsonNetReturnAttribute; System.ObjectDisposedException: Cannot access a disposed object. HOT 1
- 调用的地方比较多,有办法在LoggingFilter中获取到调用的信息 HOT 1
- 使用时报了400的错误。我不太确定我哪一步出现问题 HOT 4
- 下载路径是QT6版本的,但是实际压缩包是QT5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webapiclient.