I'm trying to develop a web request in C#/.Net by using REQBIN with the setup below. I can retrieve data as intended via REQBIN (https://reqbin.com/), but when trying to do the same using the C# code, only the regular main web page is retrieved, any ideas why?
URL: https://www.investing.com/instruments/HistoricalDataAjax
RAW: ===================
POST /instruments/HistoricalDataAjax HTTP/1.1
Host: www.investing.com
Origin: http://www.investing.com
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
Content-Length: 186
curr_id=1073048&smlID=2627117&header=SE0010296574%20Historical%20Data&st_date=04%2F12%2F2020&end_date=05%2F12%2F2021&interval_sec=Daily&sort_col=date&sort_ord=DESC&action=historical_data
CONTENT: ===================
curr_id=1073048
smlID=2627117
header=SE0010296574 Historical Data
st_date=04/12/2020
end_date=05/12/2021
interval_sec=Daily
sort_col=date
sort_ord=DESC
action=historical_data
HEADERS: ===============
Origin: http://www.investing.com
X-Requested-With: XMLHttpRequest
C# CODE: ===============
var url = "https://www.investing.com/instruments/HistoricalDataAjax";
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.Headers["Origin"] = "http://www.investing.com";
httpRequest.Headers["X-Requested-With"] = "XMLHttpRequest";
httpRequest.ContentType = "application/x-www-form-urlencoded";
var data = "curr_id=1073048&smlID=2627117&header=SE0010296574%20Historical%20Data&st_date=04%2F12%2F2020&end_date=05%2F12%2F2021&interval_sec=Daily&sort_col=date&sort_ord=DESC&action=historical_data";
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
streamWriter.Write(data);
}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
Console.WriteLine(httpResponse.StatusCode);
SHOULD-BE OUTPUT: ================== Date Price Open High Low Vol. Change % May 12, 2021 352.05 351.03 355.96 349.38 488.26K 7.59% May 11, 2021 327.21 323.34 334.99 319.16 691.09K -2.11% May 10, 2021 334.27 338.00 340.41 326.48 1.36M 15.07% May 07, 2021 290.50 288.64 291.78 282.65 620.13K -2.68% May 06, 2021 298.50 283.94 299.07 283.00 630.04K 6.80% May 05, 2021 279.49 271.03 287.75 271.03 835.71K 3.51% May 04, 2021 270.00 278.09 295.85 268.00 1.41M 2.27% May 03, 2021 264.00 256.24 264.48 254.94 1.39M 15.97% Apr 30, 2021 227.64 229.99 231.58 227.64 412.14K -0.26% Apr 29, 2021 228.23 224.41 231.16 223.89 452.54K 3.35% Apr 28, 2021 220.84 213.26 224.96 211.97 816.44K 2.48% Apr 27, 2021 215.50 210.58 216.98 209.00 521.90K 5.64% Apr 26, 2021 204.00 203.50 208.00 200.00 658.92K 9.21% Apr 23, 2021 186.80 182.48 192.86 175.80 1.83M -12.58% Apr 22, 2021 213.68 202.95 216.50 199.58 936.73K 7.06% Apr 21, 2021 199.59 190.92 202.00 185.00 899.25K 12.38% Apr 20, 2021 177.60 170.73 185.00 167.99 557.52K 1.99% Apr 19, 2021 174.14 189.40 190.33 173.62 1.07M -13.54% Apr 16, 2021 201.40 202.52 204.45 193.01 722.27K -2.50% Apr 15, 2021 206.56 205.11 207.82 200.49 610.76K 5.15% Apr 14, 2021 196.44 199.27 200.98 191.60 658.39K 3.37% Apr 13, 2021 190.04 181.39 190.63 180.71 550.55K 6.58% Apr 12, 2021 178.30 183.01 185.74 178.01 526.45K 2.89% Apr 09, 2021 173.30 174.24 177.70 172.76 379.15K 0.14% Apr 08, 2021 173.05 169.74 174.00 168.17 473.98K 1.95% Apr 07, 2021 169.74 175.99 177.39 163.36 655.48K -3.55% Apr 06, 2021 175.98 179.94 183.14 173.63 840.89K 6.72% Apr 01, 2021 164.90 164.06 168.84 163.56 402.04K 4.92% Mar 31, 2021 157.17 158.82 160.00 151.98 489.88K 0.04% Mar 30, 2021 157.10 155.22 159.75 155.22 424.23K 4.04% Mar 29, 2021 151.00 143.11 152.99 143.11 567.67K 7.20% Mar 26, 2021 140.86 136.65 140.96 136.56 266.07K 5.12% Mar 25, 2021 134.00 133.18 137.00 131.10 655.30K -6.65% Mar 24, 2021 143.55 142.01 146.43 142.01 210.81K 2.34% Mar 23, 2021 140.27 141.28 143.33 139.61 396.09K -5.86% Mar 22, 2021 149.00 151.40 151.70 148.48 276.21K -2.93% Mar 19, 2021 153.50 150.20 153.72 149.01 226.53K -0.32% Mar 18, 2021 153.99 149.89 153.99 148.13 341.22K 4.44% Mar 17, 2021 147.44 149.41 149.82 145.02 290.24K -1.52% Mar 16, 2021 149.72 149.06 151.86 147.28 285.85K 1.66% Mar 15, 2021 147.28 148.35 150.74 144.10 517.22K 0.32% Mar 12, 2021 146.81 149.00 149.94 142.82 384.18K -1.47% Mar 11, 2021 149.00 147.37 152.09 142.73 452.65K -2.96% Mar 10, 2021 153.54 151.00 154.90 150.52 393.31K 1.01% Mar 09, 2021 152.00 150.78 153.50 150.50 586.08K 4.50% Mar 08, 2021 145.45 140.25 146.40 138.48 683.40K 21.01% Mar 05, 2021 120.20 122.12 124.11 119.20 947.55K -7.48% Mar 04, 2021 129.92 130.06 132.57 125.66 357.09K -2.02% Mar 03, 2021 132.60 128.30 136.36 128.30 508.21K 4.76% Mar 02, 2021 126.58 128.22 131.89 126.25 282.20K -1.75% Mar 01, 2021 128.84 119.00 129.99 118.36 683.57K 1.35% Feb 26, 2021 127.12 115.00 128.08 114.70 1.08M -2.62% Feb 25, 2021 130.54 133.30 134.90 127.50 802.05K -4.34% Feb 24, 2021 136.46 132.74 140.16 130.31 954.89K 6.83% Feb 23, 2021 127.74 128.11 130.35 112.51 3.97M -9.40% Feb 22, 2021 141.00 154.80 154.80 129.10 3.51M -11.09% Feb 19, 2021 158.58 156.07 159.39 155.65 414.19K 1.61% Feb 18, 2021 156.06 154.50 156.94 153.19 542.54K 6.72% Feb 17, 2021 146.23 146.35 149.49 146.02 675.41K 2.33% Feb 16, 2021 142.90 146.90 147.58 142.42 492.80K -3.17% Feb 15, 2021 147.58 143.45 148.90 142.09 490.57K 0.76% Feb 12, 2021 146.46 145.47 147.50 143.00 468.45K -0.71%
Aucun commentaire:
Enregistrer un commentaire