0

I'm trying to implement a simple HttpClient request like this cURL request.

I have this CURL which runs ok:

curl "http://url.com" -H "Cookie: token=hbfoiuoi..." --data "idTienda=9734&fechaDesde=22%2F03%2F2019&fechaHasta=22%2F03%2F2019 --compressed

Response returns an Excel document:

<data contentType="application/vnd.ms-excel" contentLength="3753">UEsDBBQACAAIAM+...

But the HttpClient request not run. It doesn't return anything:

var uri = new Uri("http://url.com");
var client = new HttpClient(new HttpClientHandler { UseCookies=false});

client.BaseAddress = uri;
client.DefaultRequestHeaders.Add("Cookie", "token=hbfoiuoi...");

var parameters = new Dictionary<string, string>();
parameters.Add("id", "9734");
parameters.Add("fechaD", "22/03/2019");
parameters.Add("fechaH", "22/03/2019");
var content = new FormUrlEncodedContent(parameters);

var responsetotalSalesStore= await client.PostAsync(uri, content);
byte[] bytes = await responsetotalSalesStore.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("file.xls", bytes);

The response is:

{
   "success": false,
   "message": "null",
   "result": null,
   "limitReached": false
}
  • For sure the id is different, In curl it is `9734^` in your code it is `9734`. I suggest you use https://postb.in/ or something so you will exactly see the differences – Piotr Stapp Mar 27 '19 at 16:40
  • You have to enable cookies and include a cookie collection in the `HttpClientHandler` – Nkosi Mar 27 '19 at 16:46
  • @PiotrStapp it is the same id. I have corrected the post. thanks. – guillermo Pan Mar 27 '19 at 16:51
  • @Nkosi If I do this it doesn't access because httpclient ignore the cookie. Response is `SPNEGO authentication is not supported.SPNEGO authentication is not supported on this client.` [link](https://stackoverflow.com/a/13287224/11260529) – guillermo Pan Mar 27 '19 at 17:00

0 Answers0