Delphi Indy Send POST data in Cyrillic

风流意气都作罢 提交于 2019-12-10 18:55:28

问题


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


回答1:


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.




回答2:


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 -> София




回答3:


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.



来源:https://stackoverflow.com/questions/6750222/delphi-indy-send-post-data-in-cyrillic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!