如何使用标头中的cookie进行POST请求,例如cURL请求

时间:2019-03-27 16:30:03

标签: c# .net curl request httpclient

我正在尝试实现一个简单的 url := "https://api.binance.com/api/v1/depth?symbol=RENBTC" a, _ := http.Get(url) e, _ := ioutil.ReadAll(a.Body) var data map[string]interface{} _ = json.Unmarshal([]byte(e), &data) bid := data["bids"] fmt.Println(bid[0]) 请求,例如cURL请求。

我有一个运行正常的CURL:

HttpClient

响应返回一个Excel文档:

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

但是<data contentType="application/vnd.ms-excel" contentLength="3753">UEsDBBQACAAIAM+... 请求未运行。它不返回任何内容:

HttpClient

响应为:

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);

0 个答案:

没有答案