-
Notifications
You must be signed in to change notification settings - Fork 3
/
GetLeads.cs
executable file
·63 lines (59 loc) · 2.29 KB
/
GetLeads.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.IO;
using System.Net;
namespace GetLeads
{
class GetLeads
{
static void Main()
{
// specify URL/Component/Method and API Access Key
const string url = "https://api.idxbroker.com/leads/lead";
const string accesskey = "YourAccessKeyHere";
// instantiate new HttpWebRequest
var request = WebRequest.Create(url);
// set header information
request.ContentType = "applicaton/x-www-form-urlencoded";
request.Headers.Add("accesskey", accesskey);
// create output string objects
var responseHeaders = "";
var leads = "";
try
{
// send GET request and store response
var response = request.GetResponse();
// create stream from response
using (var responseStream = new StreamReader(response.GetResponseStream()))
{
responseHeaders = response.Headers.ToString();
leads = responseStream.ReadToEnd();
}
// dispose of response to free it for reuse
response.Close();
}
// if trying to add restricted header
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
}
// if web exception is thrown
catch (WebException e)
{
Console.WriteLine("WebException Thrown. Message: " + e.Message);
if (e.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code: " + ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description: " + ((HttpWebResponse)e.Response).StatusDescription);
Console.WriteLine("Server: " + ((HttpWebResponse)e.Response).Server);
}
}
catch (Exception e)
{
Console.WriteLine("Exception Thrown. Message: " + e.Message);
}
// print output strings
Console.WriteLine(responseHeaders);
Console.WriteLine(leads);
}
}
}