🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / webden veri getirme HttpClient Webdrive wabapi httpwebclient

1-) C# RMOS - webden veri getirme HttpClient Webdrive wabapi

 

            ServicePointManager.Expect100Continue = true;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 

            Dictionary<string, string> user = new Dictionary<string, string>();

            user.Add("username", "SEADEN");

            user.Add("password", "2021");

            user.Add("claim", "");

            user.Add("Submit", "");

            user.Add("lang", "en");

            HttpContent DictionaryItems = new FormUrlEncodedContent(user);

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://hotelstr.anextour.com");

            client.DefaultRequestHeaders.Accept.Add(

                new MediaTypeWithQualityHeaderValue("multipart/form-data"));

            client.DefaultRequestHeaders.Add("User-Agent", "C# App");

            HttpResponseMessage response = client.PostAsync("/index.php", DictionaryItems).Result;

            string result = response.Content.ReadAsStringAsync().Result;

 

            Dictionary<string, string> parameters = new Dictionary<string, string>();

            parameters.Add("DBEG", "01.09.2018");

            parameters.Add("DEND", "01.09.2019");

            parameters.Add("RDBEG", "01.09.2018");

            parameters.Add("RDEND", "01.09.2019");

            parameters.Add("HOTELINC", "1315,1316,1655,1656,1657,1602,1658,1659,1272,1309,1312,");

            parameters.Add("load", "CHECKINOUTLIST");

            parameters.Add("INOUT", "0");

            parameters.Add("CONFIRMED", "1");

            parameters.Add("WAITING", "0");

            parameters.Add("NOANSWER", "0");

            parameters.Add("NOTCONFIRMED", "0");

            parameters.Add("ORDERBYINC", "1");

            parameters.Add("random", "1574687484774");

 

 

 

 

            HttpContent DictionaryItems2 = new FormUrlEncodedContent(parameters);

            HttpResponseMessage response2 = client.PostAsync("/tourists/?", DictionaryItems2).Result;

            string result2 = response2.Content.ReadAsStringAsync().Result;

 

 

//request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

 

 

 

 

2-) örnek tabloya alma parse etme parçalama

 

 

using HtmlAgilityPack;

using RestSharp;

using RestSharp.Authenticators;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Net;

using System.Net.Http;

using System.Net.Http.Headers;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace anexEntegre

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

 

        private void btnRezGetir_Click(object sender, EventArgs e) // client.DefaultRequestHeaders.Add("User-Agent", "C# App");

        {

 

            ServicePointManager.Expect100Continue = true;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            Dictionary<string, string> user = new Dictionary<string, string>();

            user.Add("username", "SEADEN");

            user.Add("password", "2021");

            user.Add("claim", "");

            user.Add("Submit", "");

            user.Add("lang", "en");

            HttpContent DictionaryItems = new FormUrlEncodedContent(user);

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://hotelstr.anextour.com");

            client.DefaultRequestHeaders.Accept.Add(

                new MediaTypeWithQualityHeaderValue("multipart/form-data"));

            client.DefaultRequestHeaders.Add("User-Agent", "C# App");

            HttpResponseMessage response = client.PostAsync("/index.php", DictionaryItems).Result;

            string result = response.Content.ReadAsStringAsync().Result;

 

            Dictionary<string, string> parameters = new Dictionary<string, string>();

            parameters.Add("DBEG", "01.09.2018");

            parameters.Add("DEND", "01.09.2019");

            parameters.Add("RDBEG", "01.09.2018");

            parameters.Add("RDEND", "01.09.2019");

            parameters.Add("HOTELINC", "1315,1316,1655,1656,1657,1602,1658,1659,1272,1309,1312,");

            parameters.Add("load", "CHECKINOUTLIST");

            parameters.Add("INOUT", "0");

            parameters.Add("CONFIRMED", "1");

            parameters.Add("WAITING", "0");

            parameters.Add("NOANSWER", "0");

            parameters.Add("NOTCONFIRMED", "0");

            parameters.Add("ORDERBYINC", "1");

            parameters.Add("random", "1574687484774");

 

 

 

 

            HttpContent DictionaryItems2 = new FormUrlEncodedContent(parameters);

            HttpResponseMessage response2 = client.PostAsync("/tourists/?", DictionaryItems2).Result;

            string result2 = response2.Content.ReadAsStringAsync().Result;

 

            htmlParser(result2);

        }

 

 

        public void htmlParser(string htmlTable)

        {

           

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(htmlTable);

            DataTable table = new DataTable();

            foreach (var row in doc.DocumentNode.SelectNodes("//*[@id=\"row_header\"]/td"))

            {

                table.Columns.Add(row.InnerHtml.ToString());

            }

            // //*[@id="result"]/table[2]/tbody/tr[3]/td[1] //*[@id="result"]/table[2]/tbody/tr[3]

 

            int i = 0;

            bool ilkSatirEs = false;

            foreach (var row in doc.DocumentNode.SelectNodes("/table[2]/tr"))

            {

                if (i == 0)

                {

                    i++;

                    continue;

                }

                int k = 0;

                DataRow dr = table.NewRow();

 

                foreach (var row1 in row.SelectNodes("./td"))

                {

                    if (ilkSatirEs == false)

                    {

                        ilkSatirEs = true;

                        continue;

                    }

                    //Console.WriteLine(row1.InnerText);

                    dr[table.Columns[k].ColumnName] = row1.InnerText.ToString().Replace("\n","").Replace("&nbsp;", "");

                   

                    k++;

                }

                table.Rows.Add(dr);

                i++;

            }

 

            gridControl1.DataSource = table;

 

            gridView1.BestFitColumns();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

        }

    }

}

 

 2021 Ocak 18 Pazartesi
 387