Home computickets 1C Sending POST request with Base64 duty body

1C Sending POST request with Base64 duty body

Author

Date

Category

Hello.

There has been a problem with the image transfer to the web server from the program 1C 8.2.
Text data is perfectly transmitted except image.
I do this:

headerhttp = new matching ();
Headerhttp. Hold ("Content-Type", "Application / X-WWW-FORM-URLENCODED; CHARSET = UTF-8");
ServerRechnics = "port.rrham.com";
NTTR = new HTTP compound (server-class);
File = ("C: \ img22.jpg");
DD = new binary (file);
String64 = Base64 Stroke (DD);
StringPost request = "";
StringPostisType = String Poster + "& amp; image =" + String64;
Address set = "/data/api.php?call=add";
Attempt
RequestHTTP = New HTTP compound (address set, headingHttp);
QueryTtp.Sign settings (stringPostisType);
Answer HTTP = NTTR. OptionsTerage (query);
Exception
Report (Description ());
Return;
Celebrations;

And on the server everything is as usual

function Add ($ image) {
 ....
 $ file = $ _files ['image'] ['Name'];
 $ Path = '../Data/'.$UPLOAD_IMAGE.'.jpg';
 ....
 File_Put_Contents ($ Path, Base64_Decode ($ image));}

But in the end I get a broken image. I tried to save Save $ upload_image. 'Jpg'; in txt text format and noticed that there are no Some special characters in the encoding, for example + , Before sending, the plus symbol was and on the server they are missing instead of them just spaces.

Excerpt for Example
A plus symbol is
RGZ + MSNCHZC126J8Q3RT791BBE8HPBRLCGR9NJOA4JBUAX2NS8ECodDiv4 / Hevtj
The symbol plus is absent
RGZ MSNCHZC126J8Q3RT791BBE8HPBRLCGR9NJOA4JBUAX2NS8ECodDiv4 / Hevtj

Tell me what I do wrong?


Answer 1, Authority 100%

Try to send data via MultiPart / Form-Data, I work like this, example:

Cottden procedure (team)
  Address set = "/data/api.php?call=add";
  Host = "port.rrham.com";
  File = ("C: \ img22.jpg");
  DD = new binary (file);
  String64 = Base64 Stroke (DD);
  // Prepare a file with data for sending
  FIELEWORDINGS = OPERATEQUMEN File ("TXT");
  boundary = stronry (string (new unique identifier ()), "-", "");
  ViewText = New PostCext (name File, encoding.ansi, symbols. PS, lie);
  // ++ HTML Form Field
  Posttext. recruitstream ("-" + boundary);
  Posttext. recruitstream ("Content-Disposition: Form-Data; Name =" "Image" "" + symbols. PS);
  Posttext. recruitstream ("");
  Posttext. recruit Strecker (line64);
  // - HTML form field
  // Close the separator
  Posttext. recruitstream ("-" + boundary + "-");
  Posttext.Close ();
  // Define the file size
  File Management = New File (Name File);
  Size-selectivegraders = XmLest (file management. Size ());
  // Let's give data to the server
  Headlines = new matching ();
  Headers. Multiply ("Content-Type", "MultiPart / Form-Data, Boundary =" + Boundary);
  Headers. Land ("Content-Lenght", Size Layer);
  imagingOnefyle = Obvyavremian File ("TXT");
  Requestshttp = new http recorder (addressers, headlines);
  RequestTp
  Connection = new http / host);
  Answer = Compound.
Extrudresses

Answer 2

in 1C coded the variable line64 using the global context method “encoded” and then do as you wrote above, for example:

DD = new binary (file);
String64 = Base64 Stroke (DD);
** String64 = encoded (string64, POCITINGS.

if this solution helped, then do not forget to mark it with a check mark, thanks

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions