[英]Error on Indy HTTP post using TStringList as sending parameter
I have created a little program which access a webservice of mail service. 我创建了一个访问邮件服务Web服务的小程序。 The same code works on Delphi 7 with indy 9, but doesn't works with Delphi Seattle with Indy 10.
相同的代码在带有Indy 9的Delphi 7上有效,但在带有Indy 10的Delphi Seattle上无效。
My Stringlist is built that way: 我的Stringlist是这样构建的:
ParametrosConsulta.Values['nCdEmpresa'] := Edt_Cod.Text;
ParametrosConsulta.Values['&sDsSenha'] := Edt_Sen.Text;
...
My post have a sending parameter a stringlist, which has a text like that: 我的帖子有一个发送参数字符串列表,其文本如下:
nCdEmpresa= &sDsSenha= &nCdServico=41106&sCepOrigem=88905355&sCepDestino=88906768&nVlPeso=20.0&nCdFormato=1&nVlComprimento=20.0&nVlAltura=20.0&nVlLargura=20.0&nVlDiametro=6.0&sCdMaoPropria=N&nVlValorDeclarado=0&sCdAvisoRecebimento=N
then i call idHttp.Post like that, which ParametroConsulta
holds the text i've shown before, and Resposta
is a TStringStream which holds the response of the request: 然后我像这样调用idHttp.Post,其中
ParametroConsulta
保存了我之前显示的文本,而Resposta
是一个TStringStream,它保存了请求的响应:
IdHttp.Request.Clear;
IdHttp.Request.Host := 'ws.correios.com.br';
IdHttp.Request.ContentType := 'application/x-www-form-urlencoded';
idHTTP.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
IdHTTP.Request.Charset := 'utf-8';
IdHTTP.ProtocolVersion := pv1_1;
{...}
try
Application.ProcessMessages;
FrmPrincipal.Refresh;
IdHttp.Post('http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo', ParametrosConsulta, Resposta);
except
on E:EIdHttpProtocolException do
begin
ShowMessage(E.Message + ' - ' + E.ErrorMessage);
PnlEnviando.Visible := False;
Exit;
end;
end;
But after post, the webservice returns that sDsSenha
is missing (this parameter can hold a empty space). 但是发布后,Web服务将返回
sDsSenha
丢失(此参数可以保留空白空间)。
Don't write &
: 不要写
&
:
ParametrosConsulta.Values['sDsSenha'] := Edt_Sen.Text;
Ampersand are adding by Indy automatically. &符由Indy自动添加。
Btw, you may need to use TIdURI.PathEncode(Edt_Sen.Text)
for escaping some characters.顺便说一句,您可能需要使用 TIdURI.PathEncode(Edt_Sen.Text)
来转义某些字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.