Delphi Indy 以西里尔文发送 POST 数据

发布于 2024-11-25 05:27:26 字数 1510 浏览 1 评论 0原文

我想使用 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); ?>

there is the site response

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); ?>

there is the site response

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南烟雨〆相思醉 2024-12-02 05:27:26

您告诉 AddFormField() 使用 UTF-8 对文本值进行编码,然后在传输过程中使用 MIME 的 quoted-printable 编码对 UTF-8 八位字节进行额外编码,这是文本数据的 TIdFormDataField.ContentTransfer 属性的默认设置。您将在 PHP 输出中看到引用的可打印文本。如果您希望 PHP 接收原始 UTF-8 八位字节,请将 TIdFormDataField.ContentTransfer 属性设置为“8bit”或“binary”,例如:

param.AddFormField('offer[fullname]',UserArray[0], 'utf-8').ContentTransfer := '8bit';

否则,您的 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's quoted-printable encoding, which is the default setting for the TIdFormDataField.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 the TIdFormDataField.ContentTransfer property to '8bit' or 'binary' instead, eg:

param.AddFormField('offer[fullname]',UserArray[0], 'utf-8').ContentTransfer := '8bit';

Otherwise, your PHP code will have to decode the quoted-printable data using the quoted-printable-decode() function.

血之狂魔 2024-12-02 05:27:26

您的“编码符号”是 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 -> София

只是偏爱你 2024-12-02 05:27:26

PHP 服务器接收带引号的可打印格式的 UTF-8 编码字符串。要验证这一点,请检查应用程序是否在 IdMulitpartFormData 中命中此行:

FContentTransfer := sContentTransferQuotedPrintable;

但是 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:

FContentTransfer := sContentTransferQuotedPrintable;

However the PHP side should be able to handle this transfer mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文