Delphi Indy用西里尔文发送POST数据 [英] Delphi Indy Send POST data in Cyrillic
问题描述
我想使用indy 10发送带有delphi的西里尔帖子数据. 好的,我知道如何发送数据,但是当我发送书面或西里尔字母的内容时,后期数据响应中带有一些编码符号. 有我的代码
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);
这是我的POST.php的响应
this is the response from my POST.php
<?php print_r($_POST); ?>
推荐答案
您正在告诉AddFormField()
使用UTF-8编码文本值,然后在传输过程中使用MIME的quoted-printable
另外对UTF-8八位字节进行编码.编码,这是文本数据TIdFormDataField.ContentTransfer
属性的默认设置.您会在PHP输出中看到带引号的可打印文本.如果要让PHP接收原始的UTF-8八位位组,则将TIdFormDataField.ContentTransfer
属性设置为'8bit'或'binary',例如:
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';
否则,您的PHP代码将必须使用 quoted-printable-decode()函数.
Otherwise, your PHP code will have to decode the quoted-printable data using the quoted-printable-decode() function.
这篇关于Delphi Indy用西里尔文发送POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!