Delphi Can
Rest Service TBytes - Baskı Önizleme

+- Delphi Can (https://www.delphican.com)
+-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3)
+--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6)
+--- Konu Başlığı: Rest Service TBytes (/showthread.php?tid=771)



Rest Service TBytes - edo - 15-03-2017

Merhaba,

Aşağıdaki gibi bir Rest service'e TBytes tipinde bir dizi geçmeye çalışıyorum. Aşağıda oluşturmaya çalıştırdığım request var. RESTRequest1.AddBody metoduna bunu nasıl geçebilirim?


Kod:
POST http://myserver:1111//Openxxx/RecxxxLxxxPxxxx HTTP/1.1
Content-Type: text/json
Host: myserver:1111
Content-Length: 28892
Expect: 100-continue
Connection: Keep-Alive

[255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0,0,255,219,0,132,0,9,6,7,19,19,18,21,19,19,19,22,22,21,21,23,23,24,24,24,24,24,23,23,23,23,26,23,26,22,23,23,23,24,26,24,

...
...
...
0,13,208,0,2,240,32,94,46,109,109,123,147,170,23,11,54,55,239,2,211,26,157,79,130,130,252,168,127,164,63,164,41,109,204,245,62,106,51,135,12,146,63,255,217]



Rest Service TBytes - ismailkocacan - 25-10-2017

TRESTRequest tipi TCustomRESTRequest sınıfından miras alıyor ve AddBody methodunun farklı parametreler alan overload edilmiş hali mevcut.Belki parametre tipi soyut TStream tipinde olan methodu kullanabilirsiniz.Sonuç olarak TStream'den miras alan her türlü nesneyi parametre olarak geçebilirsiniz.
procedure AddBody(ABodyContent: TStream; AContentType: TRESTContentType = ctNone); overload;
Mesela elinizdeki byte array'i TStream'den miras alan TMemoryStream nesnesi içersine doldurup, bu methoda parametre olarak geçmeyi deneyebilirsiniz.
var
 Dizi: TBytes;
 Stream: TMemoryStream;
begin
 SetLength(Dizi, 2);
 Dizi[0] := 31;
 Dizi[1] := 32;

 Stream := TMemoryStream.Create;
 Stream.Write(Dizi, Length(Dizi));
 RESTRequest1.AddBody(Stream, TRESTContentType.ctMULTIPART_FORM_DATA);
 Stream.Free;
end;