TScHttpWebRequest vs multipart data

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

TScHttpWebRequest vs multipart data

Post by DmitriNL » Wed 22 Apr 2020 16:32

Hi,

Is there a clear example how to implement multipart data using TScHttpWebRequest? I found a topic but the solution does not seem to work. viewtopic.php?f=27&t=39705

I tried the TIdMultiPartFormDataStream from the Indy components to create multipart data. The multipart data is send by TScHttpWebRequest. The server does not seem to understand the result.

Code: Select all

	String FileName = "myFile.pdf";
	String URL = "https://my-url.com/";

	TScHttpWebRequest *Request = new TScHttpWebRequest(URL);
	TIdMultiPartFormDataStream *DataStream = new TIdMultiPartFormDataStream();
	try
	{
		DataStream->AddFormField("field1", "1234");
		DataStream->AddFile("file1", FileName, "application/pdf");
		DataStream->Position = 0;

		Request->Method = rmPOST;
		Request->ContentType = "multipart/form-data";
		Request->ContentLength = DataStream->Size;
		Request->SendChunked = true;
		Request->RequestStream = DataStream;

		TScHttpWebResponse *Response = Request->GetResponse();
		try
		{
			Memo1->Text = Response->ReadAsString();
		}
		__finally
		{
			Response->Free();
		}
	}
	__finally
	{
		DataStream->Free();
		Request->Free();
	}
Probably I am doing something wrong. Can you please help me out? Thank you in advance for your response.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TScHttpWebRequest vs multipart data

Post by ViktorV » Fri 24 Apr 2020 10:01

Your code is correct.
To give you a detailed answer, we need a complete example demonstrating the incorrect behavior.

Post Reply