How to send file through POST request in Zenno ?

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
Hello,


I would like to do the same API call than with CURL, in Zenno :
CURL Code:
curl -X POST -F [email protected] -F https://api-uploadcsv.com/search/csv/
How can i do that with the POST action ?

Thanks
 

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
If i convert the CURL code in C# i have this :

C#:
// In production code, don't destroy the HttpClient through using, but better use IHttpClientFactory factory or at least reuse an existing HttpClient instance

// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests

// https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

using (var httpClient = new HttpClient())

{

    using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api-uploadcsv.com/search/csv/"))

    {

        var multipartContent = new MultipartFormDataContent();

        multipartContent.Add(new ByteArrayContent(File.ReadAllBytes("search.csv")), "data", Path.GetFileName("search.csv"));

        multipartContent.Add(new StringContent("adresse"), "columns");

        multipartContent.Add(new StringContent("postcode"), "columns");

        multipartContent.Add(new StringContent("result_id"), "result_columns");

        multipartContent.Add(new StringContent("score"), "result_columns");

        request.Content = multipartContent; 


        var response = await httpClient.SendAsync(request);

    }

}
But i don't succeed to run it.

And normally the POST action is planned to managed that instead of reinvented the wheel with C# code.
 

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
So nobody has an idea to succeed that ?
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 446
Благодарностей
5 905
Баллы
113
You need to send POST request with multipart data (file in it)
I think you should just google more about post requests with multpart and how to pass a file in it.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 804
Благодарностей
1 187
Баллы
113

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
Hi, @cherubin quick forum search gave me this: https://zennolab.com/discussion/threads/c-zagruzka-fajla-zaprosom-post-multipart-form-data.94637/post-633809

You can try it. But there are other example on the forum using default zenno cubes.
What keyword did you use ? I don't know any russian words.

I find thanks Google & ChatGPT some solutions with C#, however i thought the POST action was designed to manage that kind of thing. But i don't succeed. And i tried multipart as file since the begining, without success, so i tried every option i found but i failed. That's why i'm here to ask.
And it seems the final solution is to use a specific code in a C# block.
 

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8
Here the template, just the part with the POST is failing.
 

Вложения

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 804
Благодарностей
1 187
Баллы
113
Well, I can not answer what exactly is the problem with your task. Maybe this is related to the page itself. When I try to go to this url, it does not even load api-uploadcsv.com By uploading file and tracking this manually you can get more information with help of Fiddler. Thats how you usually build request. Fidler will give you more information of what is needed to upload file in your particular case.
 

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Благодарностей
6
Баллы
8

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 804
Благодарностей
1 187
Баллы
113
No man, I did not try. Please use a forum search. There are examples of posting files with requests. As well as google with sending files as post request.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)