CharSet 被重置
CharSet gets reset
我使用以下代码初始化我的套接字
Socket:=TmyidHTTP.Create(NIL);
IOHandler:=TIdIOHandlerStack.Create(Socket);
Socket.HandleRedirects:=true;
Socket.AllowCookies:=FALSE;
Socket.ProtocolVersion:=pv1_1;
Socket.HTTPOptions:=Socket.HTTPOptions+[hoKeepOrigProtocol]+[hoNoProtocolErrorException]+[hoWantProtocolErrorContent];
Socket.Request.CustomHeaders.FoldLines:=FALSE;
Socket.Request.CharSet:='utf-8';
Socket.Request.ContentType:='text/txt';
Socket.Request.Accept:='*/*';
// Socket.ReuseSocket:=rsTrue;
Socket.Request.Connection:='keep-alive';
(TmyidHTTP 只发布受保护的DoRequest
)
但是当我查看协议时,我看到以下内容 header:charset=ISO-8859-1
。
仅当我在 post 之前再次指定 Socket.Request.CharSet:='utf-8';
时,它才有效...
知道什么是重置 CharSet 吗??
这是因为:
- 您使用的是旧版本的 Indy 10 1。
- 您正在设置
ContentType
属性 在 设置 CharSet
属性. 之后
- 您没有在
ContentType
属性 上指定 charset
属性值。
因此,在这种情况下,ContentType
属性 setter 将 CharSet
属性 重置为默认值,而不是保留当前值值。
1 这是 already fixed 2019 年 7 月的事:
Patch for Embarcadero RSP-13703. Updating various ContentType property setters to preserve an existing CharSet property value if it is already set and a new charset attribute is not being specified.
您应该使用来自 Indy GitHub repo (or, at least, apply the same fix to your existing copy and then recompile Indy) 的最新代码更新您安装的 Indy 副本。
否则,您只需将代码更改为:
- 交换两个属性赋值的顺序:
Socket.Request.ContentType:='text/txt';
Socket.Request.CharSet:='utf-8';
- 在
ContentType
赋值上指定一个 charset
属性值,这将相应地更新 CharSet
属性:
Socket.Request.ContentType:='text/txt;charset=utf-8';
我使用以下代码初始化我的套接字
Socket:=TmyidHTTP.Create(NIL);
IOHandler:=TIdIOHandlerStack.Create(Socket);
Socket.HandleRedirects:=true;
Socket.AllowCookies:=FALSE;
Socket.ProtocolVersion:=pv1_1;
Socket.HTTPOptions:=Socket.HTTPOptions+[hoKeepOrigProtocol]+[hoNoProtocolErrorException]+[hoWantProtocolErrorContent];
Socket.Request.CustomHeaders.FoldLines:=FALSE;
Socket.Request.CharSet:='utf-8';
Socket.Request.ContentType:='text/txt';
Socket.Request.Accept:='*/*';
// Socket.ReuseSocket:=rsTrue;
Socket.Request.Connection:='keep-alive';
(TmyidHTTP 只发布受保护的DoRequest
)
但是当我查看协议时,我看到以下内容 header:charset=ISO-8859-1
。
仅当我在 post 之前再次指定 Socket.Request.CharSet:='utf-8';
时,它才有效...
知道什么是重置 CharSet 吗??
这是因为:
- 您使用的是旧版本的 Indy 10 1。
- 您正在设置
ContentType
属性 在 设置CharSet
属性. 之后
- 您没有在
ContentType
属性 上指定charset
属性值。
因此,在这种情况下,ContentType
属性 setter 将 CharSet
属性 重置为默认值,而不是保留当前值值。
1 这是 already fixed 2019 年 7 月的事:
Patch for Embarcadero RSP-13703. Updating various ContentType property setters to preserve an existing CharSet property value if it is already set and a new charset attribute is not being specified.
您应该使用来自 Indy GitHub repo (or, at least, apply the same fix to your existing copy and then recompile Indy) 的最新代码更新您安装的 Indy 副本。
否则,您只需将代码更改为:
- 交换两个属性赋值的顺序:
Socket.Request.ContentType:='text/txt';
Socket.Request.CharSet:='utf-8';
- 在
ContentType
赋值上指定一个charset
属性值,这将相应地更新CharSet
属性:
Socket.Request.ContentType:='text/txt;charset=utf-8';