ReadToEnd
How do I use Read To End
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
74 | result = reader.ReadToEnd(); | 1 |
132 | string result = reader.ReadToEnd(); | 2 |
File name: AccountService.cs
Copy
59 public void RegisterByEmail(string email, Origin origin)
60 {
61 this.registrationCallback = null;
62 this.AppId = string.Empty;
63 this.Message = string.Empty;
64 this.ReturnCode = -1;
65
66 string result;
67 try
68 {
69 WebRequest req = HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin));
70 HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
71
72 // now read result
73 StreamReader reader = new StreamReader(resp.GetResponseStream());
74 result = reader.ReadToEnd();
75 }
76 catch (Exception ex)
77 {
78 this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
79 this.Exception = ex;
80 return;
81 }
82
83 this.ParseResult(result);
84 }
File name: AccountService.cs
Copy
121 private void OnRegisterByEmailCompleted(IAsyncResult ar)
122 {
123 try
124 {
125 HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
126 HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse;
127
128 if (response != null && response.StatusCode == HttpStatusCode.OK)
129 {
130 // no error. use the result
131 StreamReader reader = new StreamReader(response.GetResponseStream());
132 string result = reader.ReadToEnd();
133
134 this.ParseResult(result);
135 }
136 else
137 {
138 // a response but some error on server. show message
139 this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
140 }
141 }
142 catch (Exception ex)
143 {
144 // not even a response. show message
145 this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
146 this.Exception = ex;
147 }
148
149 if (this.registrationCallback != null)
150 {
151 this.registrationCallback(this);
152 }
153 }
ReadToEnd 157 lượt xem
Gõ tìm kiếm nhanh...