private void _futureSellBtn_Click(object sender, EventArgs e) { HttpSender http = new HttpSender("https://fincloud.apex.com.tw/FinCloud/api/GVE/PutOrder"); HttpHeaderList header = new HttpHeaderList(); header.AddHeader("Content-Type", "application/json"); header.AddHeader("Host", "fincloud.apex.com.tw"); header.AddHeader("Referer", "https://fincloud.apex.com.tw/"); header.AddHeader("User-Agent", @"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"); CookieContainer cookies = new CookieContainer(); cookies.Add(_loginCookie); PutOrderPostReq req = new PutOrderPostReq { assetcode = "TXFJ8.tw", // 期貨商品(參數) bs = "S", //買賣(參數) dt = 0, //當沖單(參數) gmrid = this._gmrid, oct = "O", on = "IOC", // ot = "MKT", //限價或市價 price = 0, //價格(參) volume = 1 //量(參) }; ResponseResult rsp = http.SendRequest(HttpRequestMethod.Post, JsonConvert.SerializeObject(req), header, cookies); }
private string _gmridApi = "http://www.fincloud.tw/FinCloud/api/GVE/GetGMRIDs"; //2019 private LoginManager() { _header = new HttpHeaderList(); _header.AddHeader("Content-Type", "application/json"); //_header.AddHeader("Host", "fincloud.apex.com.tw"); _header.AddHeader("Host", "www.fincloud.tw"); _header.AddHeader("Origin", "http://www.fincloud.tw"); //_header.AddHeader("Referer", "https://fincloud.apex.com.tw/"); // 2018 _header.AddHeader("Referer", "http://www.fincloud.tw/"); //2019 _header.AddHeader("User-Agent", @"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"); }
/// <summary> /// 解析Http Response的header /// </summary> /// <param name="response">HttpWebResponse 物件</param> /// <returns></returns> public static HttpHeaderList ParseResponseHeader(HttpWebResponse response) { HttpHeaderList headers = new HttpHeaderList(); if (response != null && response.Headers != null) { foreach (string headerKey in response.Headers.AllKeys) { headers.AddHeader(headerKey, response.Headers[headerKey]); } } return headers; }
private void sendRqBtn_Click(object sender, EventArgs e) { httpRespHeaderTxt.Clear(); if (string.IsNullOrEmpty(schemaCmb.Text)) { MessageBox.Show("請選擇要使用 [ Http ] 或是 [ Https ] !"); } if (string.IsNullOrEmpty(urlTxt.Text)) { MessageBox.Show("請填寫 URL !"); } HttpSender http = new HttpSender(); http.SetRequestEncoding(Encoding.UTF8); try { http.SetUrl(string.Format("{0}{1}", schemaCmb.Text.Trim(), urlTxt.Text.Trim())); } catch (Exception ecp) { MessageBox.Show("請檢查Url是否有填寫或是否填寫正確!"); } HttpHeaderList headers = new HttpHeaderList(); foreach (DataGridViewRow r in headerGrdVw.Rows) { if (r.Cells[0].Value != null) { headers.AddHeader(r.Cells[0].Value.ToString(), r.Cells[1].Value.ToString()); } } ResponseResult result = http.SendRequest(http.ParseHttpMethod(methodCmb.Text.ToUpper()), httpBodyTxt.Text.Trim(), headers); HttpHeaderList respHeaders = http.GetResponseHeaders(); if (respHeaders != null) { httpRespHeaderTxt.Clear(); foreach (KeyValuePair<string, string> h in respHeaders.GetHeaderCollection()) { httpRespHeaderTxt.AppendText( string.Format("{0} : {1}\r\n", h.Key, h.Value)); } } httpRespBodyTxt.Text = result.ResponseBody; }