-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForm1.cs
More file actions
51 lines (43 loc) · 1.7 KB
/
Form1.cs
File metadata and controls
51 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.IO;
using System.Net;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Authenticators;
using System.Windows.Forms;
namespace Geo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://free.ipwhois.io/json/" + textBox1.Text);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string sReadData = sr.ReadToEnd();
response.Close();
dynamic d = JsonConvert.DeserializeObject(sReadData);
label1.Text = d.city;
}
private void button2_Click(object sender, EventArgs e)
{
RestClient client = new RestClient("https://suggestions.dadata.ru/suggestions/api/4_1/rs/iplocate/address?ip="
+ textBox1.Text);
RestRequest request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "Token your_token");
IRestResponse response = client.Execute(request);
string stream = response.Content;
dynamic d = JsonConvert.DeserializeObject(stream);
label2.Text = d.location.value;
}
}
}