forked from xamarin/ios-samples
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDotNet.cs
More file actions
101 lines (90 loc) · 2.35 KB
/
Copy pathDotNet.cs
File metadata and controls
101 lines (90 loc) · 2.35 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// This file contains the sample code to use System.Net.WebRequest
// on the iPhone to communicate with HTTP and HTTPS servers
//
// Author:
// Miguel de Icaza
//
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
namespace HttpClientSample
{
public class DotNet {
AppDelegate ad;
public DotNet (AppDelegate ad)
{
this.ad = ad;
}
//
// Asynchronous HTTP request
//
public void HttpSample ()
{
Application.Busy ();
var request = WebRequest.Create (Application.WisdomUrl);
request.BeginGetResponse (FeedDownloaded, request);
}
//
// Invoked when we get the stream back from the twitter feed
// We parse the RSS feed and push the data into a
// table.
//
void FeedDownloaded (IAsyncResult result)
{
Application.Done ();
var request = result.AsyncState as HttpWebRequest;
try {
var response = request.EndGetResponse (result);
ad.RenderStream (response.GetResponseStream ());
} catch (Exception e) {
Debug.WriteLine (e);
}
}
//
// Asynchornous HTTPS request
//
public void HttpSecureSample ()
{
var https = (HttpWebRequest) WebRequest.Create ("https://gmail.com");
//
// To not depend on the root certficates, we will
// accept any certificates:
//
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, ssl) => true;
https.BeginGetResponse (GmailDownloaded, https);
}
//
// This sample just gets the result from calling
// https://gmail.com, an HTTPS secure connection,
// we do not attempt to parse the output, but merely
// dump it as text
//
void GmailDownloaded (IAsyncResult result)
{
Application.Done ();
var request = result.AsyncState as HttpWebRequest;
try {
var response = request.EndGetResponse (result);
ad.RenderStream (response.GetResponseStream ());
} catch {
// Error
}
}
//
// For an explanation of this AcceptingPolicy class, see
// http://mono-project.com/UsingTrustedRootsRespectfully
//
// This will not be needed in the future, when MonoTouch
// pulls the certificates from the iPhone directly
//
class AcceptingPolicy : ICertificatePolicy {
public bool CheckValidationResult (ServicePoint sp, X509Certificate cert, WebRequest req, int error)
{
// Trust everything
return true;
}
}
}
}