Delphi Indy 以西里尔文发送 POST 数据
我想使用 indy 10 通过 delphi 发送西里尔文帖子数据。 好吧,我知道如何发送数据,但是当我发送书面或西里尔文的内容时,发布数据响应带有一些编码符号。 这是我的代码
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
http.Request.ContentType:='multipart/form-data';
param:=TIdMultiPartFormDataStream.Create;
param.AddFormField('com','offers');
param.AddFormField('op','new');
param.AddFormField('MAX_FILE_SIZE','1048576');
param.AddFormField('offer[secid]','34');
param.AddFormField('offer[fullname]',UserArray[0], 'utf-8');
param.AddFormField('offer[email]',UserArray[1]);
param.AddFormField('offer[phone]',UserArray[2]);
param.AddFormField('offer[url]',UserArray[4]);
param.AddFormField('offer[city]','София', 'utf-8');
param.AddFormField('offer[offer_buysell]','sell');
param.AddFormField('offer[catid]','95');
param.AddFormField('offer[title]',AdArray[0], 'utf-8');
param.AddFile( 'image[0]', AdArray[3], 'image/jpeg' );
param.AddFormField('offer[description]',AdArray[1], 'utf-8');
param.AddFormField('offer[price]',AdArray[2]);
param.AddFormField('offer[offer_end]','180');
param.AddFormField('offer[email_onquestion]','1');
param.AddFormField('iagree','1');
param.AddFormField('btnSaveOffer','Изпрати', 'utf-8');
valid:=true;
url:='http://127.0.0.1/POST.php';
text:=http.Post(url,param);
,这是我的 POST.php 的响应
<?php print_r($_POST); ?>
I want to send Cyrillic post data with delphi using indy 10.
Ok i know how to send data but when i send something written or Cyrillic the post data response is with some encoded signs.
there is my code
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
http.Request.ContentType:='multipart/form-data';
param:=TIdMultiPartFormDataStream.Create;
param.AddFormField('com','offers');
param.AddFormField('op','new');
param.AddFormField('MAX_FILE_SIZE','1048576');
param.AddFormField('offer[secid]','34');
param.AddFormField('offer[fullname]',UserArray[0], 'utf-8');
param.AddFormField('offer[email]',UserArray[1]);
param.AddFormField('offer[phone]',UserArray[2]);
param.AddFormField('offer[url]',UserArray[4]);
param.AddFormField('offer[city]','София', 'utf-8');
param.AddFormField('offer[offer_buysell]','sell');
param.AddFormField('offer[catid]','95');
param.AddFormField('offer[title]',AdArray[0], 'utf-8');
param.AddFile( 'image[0]', AdArray[3], 'image/jpeg' );
param.AddFormField('offer[description]',AdArray[1], 'utf-8');
param.AddFormField('offer[price]',AdArray[2]);
param.AddFormField('offer[offer_end]','180');
param.AddFormField('offer[email_onquestion]','1');
param.AddFormField('iagree','1');
param.AddFormField('btnSaveOffer','Изпрати', 'utf-8');
valid:=true;
url:='http://127.0.0.1/POST.php';
text:=http.Post(url,param);
this is the response from my POST.php
<?php print_r($_POST); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您告诉
AddFormField()
使用 UTF-8 对文本值进行编码,然后在传输过程中使用 MIME 的quoted-printable
编码对 UTF-8 八位字节进行额外编码,这是文本数据的TIdFormDataField.ContentTransfer
属性的默认设置。您将在 PHP 输出中看到引用的可打印文本。如果您希望 PHP 接收原始 UTF-8 八位字节,请将TIdFormDataField.ContentTransfer
属性设置为“8bit”或“binary”,例如:否则,您的 PHP 代码将必须解码引用的 -使用 quoted-printable-decode() 函数。
You are telling
AddFormField()
to encode text values using UTF-8, and then the UTF-8 octets are being additionally encoded during transmission using MIME'squoted-printable
encoding, which is the default setting for theTIdFormDataField.ContentTransfer
property for text data. You are seeing the quoted-printable text in your PHP output. If you want PHP to receive raw UTF-8 octets instead, set theTIdFormDataField.ContentTransfer
property to '8bit' or 'binary' instead, eg:Otherwise, your PHP code will have to decode the quoted-printable data using the quoted-printable-decode() function.
您的“编码符号”是 UTF8 编码的西里尔字母。您可以使用对应的编码表手动解码它们。例如
D0 A1 D0 BE D1 84 D0 B8 D1 8F→新闻
Your "encoded signs" are Cyrillic in UTF8 encoding. You can decode them manually using the correspondent encoding table. For example
D0 A1 D0 BE D1 84 D0 B8 D1 8F -> София
PHP 服务器接收带引号的可打印格式的 UTF-8 编码字符串。要验证这一点,请检查应用程序是否在 IdMulitpartFormData 中命中此行:
但是 PHP 端应该能够处理此传输模式。
The PHP server receives the UTF-8 encoded strings in quoted printable format. To verify this, check if the application hits this line in IdMulitpartFormData:
However the PHP side should be able to handle this transfer mode.