how send HTML form mutltipart

guiyoteguiyote Posts: 12Member
I need to send a multipart form data, from NAV2017

The form is very easy...
<FORM action="https://cot.test.arba.gov.ar/TransporteBienes/SeguridadCliente/presentarRemitos.do"; enctype="multipart/form-data" method="POST" name="form">
<P><LABEL for="user">User: </LABEL>
<input type="text" name="user" value="" /><BR/>
<LABEL for="pass">Pass: </LABEL>
<input type="password" name="password" value="" /></P>
<input type="file" name="file" value="" /><BR/>
<input type="submit" />
</FORM>

So, in NAV I have this code (var type DotNet=> System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')...

Url:='https://cot.test.arba.gov.ar';
Method:='/TransporteBienes/SeguridadCliente/presentarRemitos.do';

HttpClient := HttpClient.HttpClient();
HttpClient.BaseAddress := Uri.Uri(Url);

myFile.TEXTMODE(TRUE);
myFile.WRITEMODE(FALSE);
myFile.OPEN('C:\Users\Public\Documents\TB_30711170XXX_000002_20190621_000001.txt');
myFile.CREATEINSTREAM(myIS);

HttpMultipartFormDataContent:=HttpMultipartFormDataContent.MultipartFormDataContent();

stringusuario:=HttpStringContent.StringContent('30711170XXX');
stringpassword:=HttpStringContent.StringContent('711XXX');
filestream:=HttpStreamContent.StreamContent(myIS);


HttpMultipartFormDataContent.Add(stringusuario,'user');
HttpMultipartFormDataContent.Add(stringpassword,'password');
HttpMultipartFormDataContent.Add(filestream,'file','C:\Users\Public\Documents\TB_30711170XXX_000002_20190621_000001.txt');

HttpResponseMessage := HttpClient.PostAsync(Method,HttpMultipartFormDataContent).Result;
varResult := HttpResponseMessage.Content.ReadAsStringAsync.Result;
MESSAGE(varResult);

The result is ERROR 87: "the multipart form submitted is incorrect"

I think the problem is that every time I invoke "HttpMultipartFormDataContent.Add" a new section of the form is generated (so in my code, I would have 3 instead of just 2)

Someone help me, please.
Sign In or Register to comment.