Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. procedure DoRequest;
  2. var
  3. Http: TIdHTTP;
  4. Params: TIdMultipartFormDataStream;
  5. RequestStream, ResponseStream: TStringStream;
  6. JRequest, JResponse: TJSONObject;
  7. url: string;
  8. begin
  9. url := 'some_custom_service'
  10.  
  11. JRequest := TJSONObject.Create;
  12. JResponse := TJSONObject.Create;
  13. try
  14. JRequest.AddPair('Pair1', 'Value1');
  15. JRequest.AddPair('Pair2', 'Value2');
  16. JRequest.AddPair('Pair3', 'Value3');
  17.  
  18. Http := TIdHTTP.Create(nil);
  19. ResponseStream := TStringStream.Create;
  20. RequestStream := TStringStream.Create(UTF8Encode(JRequest.ToString));
  21. try
  22. Params := TIdMultipartFormDataStream.Create;
  23. Params.AddFile('File', ceFileName.Text, '').ContentTransfer := '';
  24. Params.AddFormField('Json', 'application/json', '', RequestStream);
  25.  
  26. Http.Post(url, Params, ResponseStream);
  27. JResponse := TJSONObject.ParseJSONValue(ResponseStream.DataString) as TJSONObject;
  28. finally
  29. RequestStream.Free;
  30. ResponseStream.Free;
  31. Params.Free;
  32. Http.Free;
  33. end;
  34. finally
  35. JRequest.Free;
  36. JResponse.Free;
  37. end;
  38. end;
  39.  
  40. var
  41. s: String;
  42. begin
  43. s := EncodeHeader('Επιστολή εκπαιδευτικο.docx', '', 'B', 'UTF-8');
  44. ShowMessage(s); // '=?UTF-8?B?zpXPgM65z4PPhM6/zrvOriDOtc66z4DOsc65zrTOtc+Fz4TOuc66zr8uZG9j?='#13#10' =?UTF-8?B?eA==?='
  45. s := DecodeHeader(s);
  46. ShowMessage(s); // 'Επιστολή εκπαιδευτικο.docx'
  47.  
  48. s := EncodeHeader('Επιστολή εκπαιδευτικ.docx', '', 'B', 'UTF-8');
  49. ShowMessage(s); // '=?UTF-8?B?zpXPgM65z4PPhM6/zrvOriDOtc66z4DOsc65zrTOtc+Fz4TOuc66LmRvY3g=?='
  50. s := DecodeHeader(s);
  51. ShowMessage(s); // 'Επιστολή εκπαιδευτικ.docx'
  52.  
  53. s := EncodeHeader('Επιστολή εκπαιδευτικ .docx', '', 'B', 'UTF-8');
  54. ShowMessage(s); // '=?UTF-8?B?zpXPgM65z4PPhM6/zrvOriDOtc66z4DOsc65zrTOtc+Fz4TOuc66?= .docx'
  55. s := DecodeHeader(s);
  56. ShowMessage(s); // 'Επιστολή εκπαιδευτικ .docx'
  57. end;
  58.  
  59. with Params.AddFile('File', ceFileName.Text, '') do
  60. begin
  61. ContentTransfer := '';
  62. HeaderEncoding := 'Q'; // <--- here
  63. HeaderCharSet := 'utf-8';
  64. end;
  65.  
  66. with Params.AddFile('File', ceFileName.Text, '') do
  67. begin
  68. ContentTransfer := '';
  69. HeaderEncoding := '8'; // <--- here
  70. HeaderCharSet := 'utf-8';
  71. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement