You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-11-27 22:18:36 +02:00
Main build (Jenkins)
This commit is contained in:
4
docs/en/data/HTTPClient/AddMultipartFormDataField.json
vendored
Normal file
4
docs/en/data/HTTPClient/AddMultipartFormDataField.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
4
docs/en/data/HTTPClient/AddMultipartFormDataFile.json
vendored
Normal file
4
docs/en/data/HTTPClient/AddMultipartFormDataFile.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
3
docs/en/data/HTTPClient/SetFormBody.json
vendored
Normal file
3
docs/en/data/HTTPClient/SetFormBody.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
3
docs/en/data/HTTPClient/SetJsonBody.json
vendored
Normal file
3
docs/en/data/HTTPClient/SetJsonBody.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
3
docs/en/data/HTTPClient/SetStringBody.json
vendored
Normal file
3
docs/en/data/HTTPClient/SetStringBody.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
4
docs/en/data/HTTPClient/StartMultipartBody.json
vendored
Normal file
4
docs/en/data/HTTPClient/StartMultipartBody.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Image": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
13
docs/en/examples/HTTPClient/AddMultipartFormDataField.txt
vendored
Normal file
13
docs/en/examples/HTTPClient/AddMultipartFormDataField.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text") // <---
|
||||
.AddMultipartFormDataField("Field2", "10") // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
13
docs/en/examples/HTTPClient/AddMultipartFormDataFile.txt
vendored
Normal file
13
docs/en/examples/HTTPClient/AddMultipartFormDataFile.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
10
docs/en/examples/HTTPClient/SetFormBody.txt
vendored
Normal file
10
docs/en/examples/HTTPClient/SetFormBody.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Data = New Structure("Field1,Field2", "10", "Text");
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetFormBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
15
docs/en/examples/HTTPClient/SetJsonBody.txt
vendored
Normal file
15
docs/en/examples/HTTPClient/SetJsonBody.txt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
RandomArray = New Array;
|
||||
RandomArray.Add("A");
|
||||
RandomArray.Add("B");
|
||||
RandomArray.Add("C");
|
||||
|
||||
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetJsonBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
12
docs/en/examples/HTTPClient/SetStringBody.txt
vendored
Normal file
12
docs/en/examples/HTTPClient/SetStringBody.txt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Text = "Hello world!";
|
||||
Encoding = "Windows-1251";
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.UseEncoding(Encoding)
|
||||
.SetStringBody(Text) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
13
docs/en/examples/HTTPClient/StartMultipartBody.txt
vendored
Normal file
13
docs/en/examples/HTTPClient/StartMultipartBody.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody() // <---
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
4
docs/ru/data/HTTPКлиент/ДобавитьПолеMultipartFormData.json
vendored
Normal file
4
docs/ru/data/HTTPКлиент/ДобавитьПолеMultipartFormData.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
4
docs/ru/data/HTTPКлиент/ДобавитьФайлMultipartFormData.json
vendored
Normal file
4
docs/ru/data/HTTPКлиент/ДобавитьФайлMultipartFormData.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
4
docs/ru/data/HTTPКлиент/НачатьЗаписьТелаMultipart.json
vendored
Normal file
4
docs/ru/data/HTTPКлиент/НачатьЗаписьТелаMultipart.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"URL": "https://httpbin.org",
|
||||
"Картинка": "https://api.athenaeum.digital/test_data/picture.jpg"
|
||||
}
|
||||
3
docs/ru/data/HTTPКлиент/УстановитьFormТело.json
vendored
Normal file
3
docs/ru/data/HTTPКлиент/УстановитьFormТело.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
3
docs/ru/data/HTTPКлиент/УстановитьJsonТело.json
vendored
Normal file
3
docs/ru/data/HTTPКлиент/УстановитьJsonТело.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
3
docs/ru/data/HTTPКлиент/УстановитьСтроковоеТело.json
vendored
Normal file
3
docs/ru/data/HTTPКлиент/УстановитьСтроковоеТело.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"URL": "https://httpbin.org"
|
||||
}
|
||||
13
docs/ru/examples/HTTPКлиент/ДобавитьПолеMultipartFormData.txt
vendored
Normal file
13
docs/ru/examples/HTTPКлиент/ДобавитьПолеMultipartFormData.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.НачатьЗаписьТелаMultipart()
|
||||
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png")
|
||||
.ДобавитьПолеMultipartFormData("Поле1", "Текст") // <---
|
||||
.ДобавитьПолеMultipartFormData("Поле2", "10") // <---
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
13
docs/ru/examples/HTTPКлиент/ДобавитьФайлMultipartFormData.txt
vendored
Normal file
13
docs/ru/examples/HTTPКлиент/ДобавитьФайлMultipartFormData.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.НачатьЗаписьТелаMultipart()
|
||||
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png") // <---
|
||||
.ДобавитьПолеMultipartFormData("Поле1", "Текст")
|
||||
.ДобавитьПолеMultipartFormData("Поле2", "10")
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
13
docs/ru/examples/HTTPКлиент/НачатьЗаписьТелаMultipart.txt
vendored
Normal file
13
docs/ru/examples/HTTPКлиент/НачатьЗаписьТелаMultipart.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Картинка = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Путь или Двоичные данные
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.НачатьЗаписьТелаMultipart() // <---
|
||||
.ДобавитьФайлMultipartFormData("file1", "pic.png", Картинка, "image/png")
|
||||
.ДобавитьПолеMultipartFormData("Поле1", "Текст")
|
||||
.ДобавитьПолеMultipartFormData("Поле2", "10")
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
10
docs/ru/examples/HTTPКлиент/УстановитьFormТело.txt
vendored
Normal file
10
docs/ru/examples/HTTPКлиент/УстановитьFormТело.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Данные = Новый Структура("Поле1,Поле2", "10", "Текст");
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.УстановитьFormТело(Данные) // <---
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
15
docs/ru/examples/HTTPКлиент/УстановитьJsonТело.txt
vendored
Normal file
15
docs/ru/examples/HTTPКлиент/УстановитьJsonТело.txt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
СлучайныйМассив = Новый Массив;
|
||||
СлучайныйМассив.Добавить("A");
|
||||
СлучайныйМассив.Добавить("B");
|
||||
СлучайныйМассив.Добавить("C");
|
||||
|
||||
Данные = Новый Структура("Поле1,Поле2,Поле3", 10, "Текст", СлучайныйМассив);
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.УстановитьJsonТело(Данные) // <---
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
12
docs/ru/examples/HTTPКлиент/УстановитьСтроковоеТело.txt
vendored
Normal file
12
docs/ru/examples/HTTPКлиент/УстановитьСтроковоеТело.txt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
URL = "https://httpbin.org";
|
||||
URL = URL + "/post";
|
||||
|
||||
Текст = "Привет мир!";
|
||||
Кодировка = "Windows-1251";
|
||||
|
||||
Результат = OPI_ЗапросыHTTP.НовыйЗапрос()
|
||||
.Инициализировать(URL)
|
||||
.ИспользоватьКодировку(Кодировка)
|
||||
.УстановитьСтроковоеТело(Текст) // <---
|
||||
.ОбработатьЗапрос("POST")
|
||||
.ВернутьОтветКакJSONКоллекцию();
|
||||
14526
service/dictionaries/en.json
vendored
14526
service/dictionaries/en.json
vendored
File diff suppressed because it is too large
Load Diff
285
src/en/OInt/tests/Modules/internal/OPI_Tests.os
vendored
285
src/en/OInt/tests/Modules/internal/OPI_Tests.os
vendored
@@ -2643,6 +2643,12 @@ Procedure HTTP_BodySet() Export
|
||||
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
|
||||
|
||||
HTTPClient_SetBinaryBody(TestParameters);
|
||||
HTTPClient_SetStringBody(TestParameters);
|
||||
HTTPClient_SetJsonBody(TestParameters);
|
||||
HTTPClient_SetFormBody(TestParameters);
|
||||
HTTPClient_StartMultipartBody(TestParameters);
|
||||
HTTPClient_AddMultipartFormDataField(TestParameters);
|
||||
HTTPClient_AddMultipartFormDataFile(TestParameters);
|
||||
|
||||
EndProcedure
|
||||
|
||||
@@ -21072,7 +21078,11 @@ Procedure HTTPClient_Initialize(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Try
|
||||
@@ -21130,7 +21140,11 @@ Procedure HTTPClient_SetURL(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Try
|
||||
@@ -21184,7 +21198,11 @@ Procedure HTTPClient_SetURLParams(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Address = "/get?param1=text¶m2=10";
|
||||
@@ -21400,7 +21418,11 @@ Procedure HTTPClient_SetDataType(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetDataType", "HTTPClient");
|
||||
@@ -21448,7 +21470,11 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
|
||||
Result["data"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetBinaryBody", "HTTPClient");
|
||||
@@ -21462,6 +21488,265 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetStringBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Text = "Hello world!";
|
||||
Encoding = "Windows-1251";
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.UseEncoding(Encoding)
|
||||
.SetStringBody(Text) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);
|
||||
|
||||
TextBD = ПолучитьДвоичныеДанныеИзСтроки(Text, Encoding);
|
||||
Size = TextBD.Size();
|
||||
OPI_TypeConversion.GetLine(Size);
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);
|
||||
|
||||
TextB64 = "data:application/octet-stream;base64," + Base64String(TextBD);
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["data"]).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetJsonBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
RandomArray = New Array;
|
||||
RandomArray.Add("A");
|
||||
RandomArray.Add("B");
|
||||
RandomArray.Add("C");
|
||||
|
||||
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetJsonBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/json; charset=utf-8");
|
||||
|
||||
JSONResult = Result["json"];
|
||||
JSONOriginal = Data;
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field1"]).Равно(JSONOriginal["Field1"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field2"]).Равно(JSONOriginal["Field2"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][0]).Равно(JSONOriginal["Field3"][0]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][1]).Равно(JSONOriginal["Field3"][1]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][2]).Равно(JSONOriginal["Field3"][2]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetFormBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Data = New Structure("Field1,Field2", "10", "Text");
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetFormBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetFormBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/x-www-form-urlencoded; charset=utf-8");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно(Data["Field1"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно(Data["Field2"]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_StartMultipartBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody() // <---
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "StartMultipartBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_AddMultipartFormDataFile(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataFile", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_AddMultipartFormDataField(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text") // <---
|
||||
.AddMultipartFormDataField("Field2", "10") // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(ПолучитьСтрокуИзДвоичныхДанных(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataField", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
@@ -294,6 +294,48 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Settings
|
||||
|
||||
Function UseEncoding(Val Encoding) Export
|
||||
|
||||
Try
|
||||
|
||||
If StopExecution() Then Return ЭтотОбъект EndIf;
|
||||
|
||||
AddLog("UseEncoding: Setting the value");
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
|
||||
SetSetting("EncodeRequestBody", Encoding);
|
||||
|
||||
Return ЭтотОбъект;
|
||||
|
||||
Except
|
||||
Return Error(DetailErrorDescription(ErrorInfo()));
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UseGzipCompression(Val Flag) Export
|
||||
|
||||
Try
|
||||
|
||||
If StopExecution() Then Return ЭтотОбъект EndIf;
|
||||
|
||||
AddLog("UseGzipCompression: Setting the value");
|
||||
OPI_TypeConversion.GetBoolean(Flag);
|
||||
|
||||
SetSetting("gzip", Flag);
|
||||
|
||||
Return ЭтотОбъект;
|
||||
|
||||
Except
|
||||
Return Error(DetailErrorDescription(ErrorInfo()));
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region BodySet
|
||||
|
||||
// Set binary body !NOCLI
|
||||
@@ -350,12 +392,11 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Data - String - Request body data - data
|
||||
// Encoding - String - String encoding - enc
|
||||
// WriteBOM - Boolean - True > BOM will be added - bom
|
||||
//
|
||||
// Returns:
|
||||
// DataProcessorObject.OPI_HTTPClient - This processor object
|
||||
Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) Export
|
||||
Function SetStringBody(Val Data, Val WriteBOM = False) Export
|
||||
|
||||
Try
|
||||
|
||||
@@ -368,12 +409,16 @@ Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) E
|
||||
Return ЭтотОбъект;
|
||||
EndIf;
|
||||
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
|
||||
If Not RequestTypeSetManualy Then
|
||||
RequestDataType = "text/plain; charset=utf-8";
|
||||
RequestDataType = StrTemplate("text/plain; charset=%1", Encoding);
|
||||
EndIf;
|
||||
|
||||
AddLog("SetStringBody: Beginning of body setting");
|
||||
SetBodyFromString(Data, Encoding, WriteBOM);
|
||||
SetBodyFromString(Data, WriteBOM);
|
||||
AddLog(StrTemplate("SetStringBody: Body set, size %1", RequestBody.Size()));
|
||||
|
||||
Return ЭтотОбъект;
|
||||
@@ -500,7 +545,8 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
Multipart = True;
|
||||
Boundary = StrReplace(String(New UUID), "-", "");
|
||||
LineSeparator = Chars.CR + Chars.LF;
|
||||
RequestDataType = StrTemplate("multipart/%1; boundary=%2", View, Boundary);
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
RequestDataType = StrTemplate("multipart/%1; boundary=%2; charset=%3", View, Boundary, Encoding);
|
||||
|
||||
If UseFile Then
|
||||
|
||||
@@ -509,7 +555,7 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
RequestBodyFile = GetTempFileName();
|
||||
BodyTemporaryFile = True;
|
||||
RequestDataWriter = New DataWriter(RequestBodyFile
|
||||
, TextEncoding.UTF8
|
||||
, Encoding
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
, False
|
||||
@@ -523,13 +569,12 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
RequestBodyStream = New MemoryStream();
|
||||
|
||||
RequestDataWriter = New DataWriter(RequestBodyStream
|
||||
, TextEncoding.UTF8
|
||||
, Encoding
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
, ""
|
||||
, False);
|
||||
|
||||
|
||||
EndIf;
|
||||
|
||||
Return ЭтотОбъект;
|
||||
@@ -1090,7 +1135,7 @@ Function ConvertParameterToString(Val Value)
|
||||
OPI_TypeConversion.GetLine(Value);
|
||||
|
||||
If EncodeURL Then
|
||||
Value = EncodeString(Value, StringEncodingMethod.URLInURLEncoding);
|
||||
Value = EncodeString(Value, StringEncodingMethod.URLencoding);
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
@@ -1108,9 +1153,10 @@ Function SetBodyFromBinary(Val Value)
|
||||
|
||||
EndFunction
|
||||
|
||||
Function SetBodyFromString(Val Value, Val Encoding = "UTF-8", Val WriteBOM = False)
|
||||
Function SetBodyFromString(Val Value, Val WriteBOM = False)
|
||||
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
OPI_TypeConversion.GetLine(Value);
|
||||
OPI_TypeConversion.GetBoolean(WriteBOM);
|
||||
|
||||
@@ -1423,12 +1469,21 @@ EndFunction
|
||||
|
||||
Function GetResponseBody()
|
||||
|
||||
GZip = "gzip";
|
||||
NeedsUnpacking = False;
|
||||
|
||||
Header1 = Response.Headers.Get("Content-Encoding");
|
||||
Header2 = Response.Headers.Get("content-encoding");
|
||||
For Each ResponseHeader In Response.Headers Do
|
||||
|
||||
NeedsUnpacking = Header1 = GZip Or Header2 = GZip;
|
||||
HeaderKey = ResponseHeader.Key;
|
||||
HeaderValue = ResponseHeader.Value;
|
||||
|
||||
If Lower(HeaderKey) = "content-encoding" Then
|
||||
If Lower(HeaderValue) = "gzip" Then
|
||||
NeedsUnpacking = True;
|
||||
Break;
|
||||
EndIf;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If NeedsUnpacking Then
|
||||
Data = UnpackResponse(Response);
|
||||
@@ -2121,12 +2176,17 @@ Function GetSetting(Val SettingKey)
|
||||
Return Settings[SettingKey];
|
||||
EndFunction
|
||||
|
||||
Procedure SetSetting(Val SettingKey, Val Value)
|
||||
Settings[SettingKey] = Value;
|
||||
EndProcedure
|
||||
|
||||
Procedure SetDefaultSettings()
|
||||
|
||||
Settings = New Structure;
|
||||
Settings.Insert("gzip" , True);
|
||||
Settings.Insert("SplitArrayParams" , False);
|
||||
Settings.Insert("URLencoding" , True);
|
||||
Settings.Insert("EncodeRequestBody" , "UTF-8");
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
||||
285
src/en/OPI/src/CommonModules/OPI_Tests/Module.bsl
vendored
285
src/en/OPI/src/CommonModules/OPI_Tests/Module.bsl
vendored
@@ -2643,6 +2643,12 @@ Procedure HTTP_BodySet() Export
|
||||
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
|
||||
|
||||
HTTPClient_SetBinaryBody(TestParameters);
|
||||
HTTPClient_SetStringBody(TestParameters);
|
||||
HTTPClient_SetJsonBody(TestParameters);
|
||||
HTTPClient_SetFormBody(TestParameters);
|
||||
HTTPClient_StartMultipartBody(TestParameters);
|
||||
HTTPClient_AddMultipartFormDataField(TestParameters);
|
||||
HTTPClient_AddMultipartFormDataFile(TestParameters);
|
||||
|
||||
EndProcedure
|
||||
|
||||
@@ -21072,7 +21078,11 @@ Procedure HTTPClient_Initialize(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Try
|
||||
@@ -21130,7 +21140,11 @@ Procedure HTTPClient_SetURL(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Try
|
||||
@@ -21184,7 +21198,11 @@ Procedure HTTPClient_SetURLParams(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
Address = "/get?param1=text¶m2=10";
|
||||
@@ -21400,7 +21418,11 @@ Procedure HTTPClient_SetDataType(FunctionParameters)
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetDataType", "HTTPClient");
|
||||
@@ -21448,7 +21470,11 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
|
||||
Result["data"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetBinaryBody", "HTTPClient");
|
||||
@@ -21462,6 +21488,265 @@ Procedure HTTPClient_SetBinaryBody(FunctionParameters)
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetStringBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Text = "Hello world!";
|
||||
Encoding = "Windows-1251";
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.UseEncoding(Encoding)
|
||||
.SetStringBody(Text) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("text/plain; charset=" + Encoding);
|
||||
|
||||
TextBD = GetBinaryDataFromString(Text, Encoding);
|
||||
Size = TextBD.Size();
|
||||
OPI_TypeConversion.GetLine(Size);
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Length"]).Равно(Size);
|
||||
|
||||
TextB64 = "data:application/octet-stream;base64," + Base64String(TextBD);
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["data"]).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetJsonBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
RandomArray = New Array;
|
||||
RandomArray.Add("A");
|
||||
RandomArray.Add("B");
|
||||
RandomArray.Add("C");
|
||||
|
||||
Data = New Structure("Field1,Field2,Field3", 10, "Text", RandomArray);
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetJsonBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetStringBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/json; charset=utf-8");
|
||||
|
||||
JSONResult = Result["json"];
|
||||
JSONOriginal = Data;
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field1"]).Равно(JSONOriginal["Field1"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field2"]).Равно(JSONOriginal["Field2"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][0]).Равно(JSONOriginal["Field3"][0]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][1]).Равно(JSONOriginal["Field3"][1]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(JSONResult["Field3"][2]).Равно(JSONOriginal["Field3"][2]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_SetFormBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Data = New Structure("Field1,Field2", "10", "Text");
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.SetFormBody(Data) // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "SetFormBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["headers"]["Content-Type"]).Равно("application/x-www-form-urlencoded; charset=utf-8");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно(Data["Field1"]);
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно(Data["Field2"]);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_StartMultipartBody(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody() // <---
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "StartMultipartBody", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_AddMultipartFormDataFile(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
|
||||
.AddMultipartFormDataField("Field1", "Text")
|
||||
.AddMultipartFormDataField("Field2", "10")
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataFile", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure HTTPClient_AddMultipartFormDataField(FunctionParameters)
|
||||
|
||||
URL = FunctionParameters["HTTP_URL"];
|
||||
URL = URL + "/post";
|
||||
|
||||
Image = FunctionParameters["Picture"]; // URL, Path or Binary Data
|
||||
|
||||
Result = OPI_HTTPRequests.NewRequest()
|
||||
.Initialize(URL)
|
||||
.StartMultipartBody()
|
||||
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png")
|
||||
.AddMultipartFormDataField("Field1", "Text") // <---
|
||||
.AddMultipartFormDataField("Field2", "10") // <---
|
||||
.ProcessRequest("POST")
|
||||
.ReturnResponseAsJSONObject();
|
||||
|
||||
// END
|
||||
|
||||
Try
|
||||
Result["origin"] = "***";
|
||||
ResponseFile = Result["files"]["file1"];
|
||||
Result["files"]["file1"] = "...";
|
||||
Except
|
||||
Message("Cant replace origin");
|
||||
|
||||
Try
|
||||
Message(Result.GetLog(True));
|
||||
Except
|
||||
Message(GetStringFromBinaryData(Result));
|
||||
EndTry;
|
||||
EndTry;
|
||||
|
||||
OPI_TestDataRetrieval.WriteLog(Result, "AddMultipartFormDataField", "HTTPClient");
|
||||
OPI_TestDataRetrieval.ExpectsThat(StrStartsWith(Result["headers"]["Content-Type"], "multipart/")).Равно(True);
|
||||
|
||||
OPI_TypeConversion.GetBinaryData(Image);
|
||||
TextB64 = "data:image/png;base64," + Base64String(Image);
|
||||
TextB64 = StrReplace(TextB64, Chars.CR + Chars.LF, "");
|
||||
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field1"]).Равно("Text");
|
||||
OPI_TestDataRetrieval.ExpectsThat(Result["form"]["Field2"]).Равно("10");
|
||||
OPI_TestDataRetrieval.ExpectsThat(ResponseFile).Равно(TextB64);
|
||||
|
||||
EndProcedure
|
||||
|
||||
#EndRegion
|
||||
|
||||
#EndRegion
|
||||
|
||||
@@ -294,6 +294,48 @@ EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region Settings
|
||||
|
||||
Function UseEncoding(Val Encoding) Export
|
||||
|
||||
Try
|
||||
|
||||
If StopExecution() Then Return ThisObject EndIf;
|
||||
|
||||
AddLog("UseEncoding: Setting the value");
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
|
||||
SetSetting("EncodeRequestBody", Encoding);
|
||||
|
||||
Return ThisObject;
|
||||
|
||||
Except
|
||||
Return Error(DetailErrorDescription(ErrorInfo()));
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
Function UseGzipCompression(Val Flag) Export
|
||||
|
||||
Try
|
||||
|
||||
If StopExecution() Then Return ThisObject EndIf;
|
||||
|
||||
AddLog("UseGzipCompression: Setting the value");
|
||||
OPI_TypeConversion.GetBoolean(Flag);
|
||||
|
||||
SetSetting("gzip", Flag);
|
||||
|
||||
Return ThisObject;
|
||||
|
||||
Except
|
||||
Return Error(DetailErrorDescription(ErrorInfo()));
|
||||
EndTry;
|
||||
|
||||
EndFunction
|
||||
|
||||
#EndRegion
|
||||
|
||||
#Region BodySet
|
||||
|
||||
// Set binary body !NOCLI
|
||||
@@ -350,12 +392,11 @@ EndFunction
|
||||
//
|
||||
// Parameters:
|
||||
// Data - String - Request body data - data
|
||||
// Encoding - String - String encoding - enc
|
||||
// WriteBOM - Boolean - True > BOM will be added - bom
|
||||
//
|
||||
// Returns:
|
||||
// DataProcessorObject.OPI_HTTPClient - This processor object
|
||||
Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) Export
|
||||
Function SetStringBody(Val Data, Val WriteBOM = False) Export
|
||||
|
||||
Try
|
||||
|
||||
@@ -368,12 +409,16 @@ Function SetStringBody(Val Data, Val Encoding = "UTF-8", Val WriteBOM = False) E
|
||||
Return ThisObject;
|
||||
EndIf;
|
||||
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
|
||||
If Not RequestTypeSetManualy Then
|
||||
RequestDataType = "text/plain; charset=utf-8";
|
||||
RequestDataType = StrTemplate("text/plain; charset=%1", Encoding);
|
||||
EndIf;
|
||||
|
||||
AddLog("SetStringBody: Beginning of body setting");
|
||||
SetBodyFromString(Data, Encoding, WriteBOM);
|
||||
SetBodyFromString(Data, WriteBOM);
|
||||
AddLog(StrTemplate("SetStringBody: Body set, size %1", RequestBody.Size()));
|
||||
|
||||
Return ThisObject;
|
||||
@@ -500,7 +545,8 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
Multipart = True;
|
||||
Boundary = StrReplace(String(New UUID), "-", "");
|
||||
LineSeparator = Chars.CR + Chars.LF;
|
||||
RequestDataType = StrTemplate("multipart/%1; boundary=%2", View, Boundary);
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
RequestDataType = StrTemplate("multipart/%1; boundary=%2; charset=%3", View, Boundary, Encoding);
|
||||
|
||||
If UseFile Then
|
||||
|
||||
@@ -509,7 +555,7 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
RequestBodyFile = GetTempFileName();
|
||||
BodyTemporaryFile = True;
|
||||
RequestDataWriter = New DataWriter(RequestBodyFile
|
||||
, TextEncoding.UTF8
|
||||
, Encoding
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
, False
|
||||
@@ -523,13 +569,12 @@ Function StartMultipartBody(UseFile = True, Val View = "form-data") Export
|
||||
RequestBodyStream = New MemoryStream();
|
||||
|
||||
RequestDataWriter = New DataWriter(RequestBodyStream
|
||||
, TextEncoding.UTF8
|
||||
, Encoding
|
||||
, ByteOrder.LittleEndian
|
||||
, ""
|
||||
, ""
|
||||
, False);
|
||||
|
||||
|
||||
EndIf;
|
||||
|
||||
Return ThisObject;
|
||||
@@ -1090,7 +1135,7 @@ Function ConvertParameterToString(Val Value)
|
||||
OPI_TypeConversion.GetLine(Value);
|
||||
|
||||
If EncodeURL Then
|
||||
Value = EncodeString(Value, StringEncodingMethod.URLInURLEncoding);
|
||||
Value = EncodeString(Value, StringEncodingMethod.URLencoding);
|
||||
EndIf;
|
||||
|
||||
EndIf;
|
||||
@@ -1108,9 +1153,10 @@ Function SetBodyFromBinaryData(Val Value)
|
||||
|
||||
EndFunction
|
||||
|
||||
Function SetBodyFromString(Val Value, Val Encoding = "UTF-8", Val WriteBOM = False)
|
||||
Function SetBodyFromString(Val Value, Val WriteBOM = False)
|
||||
|
||||
Encoding = GetSetting("EncodeRequestBody");
|
||||
|
||||
OPI_TypeConversion.GetLine(Encoding);
|
||||
OPI_TypeConversion.GetLine(Value);
|
||||
OPI_TypeConversion.GetBoolean(WriteBOM);
|
||||
|
||||
@@ -1423,12 +1469,21 @@ EndFunction
|
||||
|
||||
Function GetResponseBody()
|
||||
|
||||
GZip = "gzip";
|
||||
NeedsUnpacking = False;
|
||||
|
||||
Header1 = Response.Headers.Get("Content-Encoding");
|
||||
Header2 = Response.Headers.Get("content-encoding");
|
||||
For Each ResponseHeader In Response.Headers Do
|
||||
|
||||
NeedsUnpacking = Header1 = GZip Or Header2 = GZip;
|
||||
HeaderKey = ResponseHeader.Key;
|
||||
HeaderValue = ResponseHeader.Value;
|
||||
|
||||
If Lower(HeaderKey) = "content-encoding" Then
|
||||
If Lower(HeaderValue) = "gzip" Then
|
||||
NeedsUnpacking = True;
|
||||
Break;
|
||||
EndIf;
|
||||
EndIf;
|
||||
|
||||
EndDo;
|
||||
|
||||
If NeedsUnpacking Then
|
||||
Data = UnpackResponse(Response);
|
||||
@@ -2121,12 +2176,17 @@ Function GetSetting(Val SettingKey)
|
||||
Return Settings[SettingKey];
|
||||
EndFunction
|
||||
|
||||
Procedure SetSetting(Val SettingKey, Val Value)
|
||||
Settings[SettingKey] = Value;
|
||||
EndProcedure
|
||||
|
||||
Procedure SetDefaultSettings()
|
||||
|
||||
Settings = New Structure;
|
||||
Settings.Insert("gzip" , True);
|
||||
Settings.Insert("SplitArrayParams" , False);
|
||||
Settings.Insert("URLencoding" , True);
|
||||
Settings.Insert("EncodeRequestBody" , "UTF-8");
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/tests/Modules/internal/OPI_Тесты.os
|
||||
// OneScript: ./OInt/tests/Modules/internal/OPI_Тесты.os
|
||||
|
||||
// MIT License
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// OneScript: ./OInt/tools/Modules/internal/Classes/OPI_HTTPКлиент.os
|
||||
// OneScript: ./OInt/tools/Modules/internal/Classes/OPI_HTTPКлиент.os
|
||||
|
||||
// MIT License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user