public async Task RegisterExternal( string username) { string uri = String.Format("{0}/api/Account/RegisterExternal", BaseUri); RegisterExternalBindingModel model = new RegisterExternalBindingModel { UserName = username }; HttpWebRequest request = new HttpWebRequest(new Uri(uri)); request.ContentType = "application/json"; request.Accept = "application/json"; request.Headers.Add("Authorization", String.Format("Bearer {0}", AccessToken)); request.Method = "POST"; string postJson = JsonConvert.SerializeObject(model); byte[] bytes = Encoding.UTF8.GetBytes(postJson); using (Stream requestStream = await request.GetRequestStreamAsync()) { requestStream.Write(bytes, 0, bytes.Length); } try { WebResponse response = await request.GetResponseAsync(); HttpWebResponse httpResponse = (HttpWebResponse)response; string result; using (Stream responseStream = httpResponse.GetResponseStream()) { result = new StreamReader(responseStream).ReadToEnd(); Console.WriteLine(result); } } catch (SecurityException) { throw; } catch (Exception ex) { throw new InvalidOperationException("Unable to register user", ex); } }
public async Task RegisterExternal( string username) { string uri = String.Format("{0}/api/Account/RegisterExternal", BaseUri); RegisterExternalBindingModel model = new RegisterExternalBindingModel { UserName = username }; HttpWebRequest request = new HttpWebRequest(new Uri(uri)); request.ContentType = "application/json"; request.Accept = "application/json"; request.Headers.Add("Authorization", String.Format("Bearer {0}", AccessToken)); request.Method = "POST"; string postJson = JsonConvert.SerializeObject(model); byte[] bytes = Encoding.UTF8.GetBytes(postJson); using (Stream requestStream = await request.GetRequestStreamAsync()) { requestStream.Write(bytes, 0, bytes.Length); } try { WebResponse response = await request.GetResponseAsync(); HttpWebResponse httpResponse = (HttpWebResponse)response; string result; using (Stream responseStream = httpResponse.GetResponseStream()) { result = new StreamReader(responseStream).ReadToEnd(); Console.WriteLine(result); } } catch (SecurityException) { throw; } catch (Exception ex) { throw new InvalidOperationException("Unable to register user", ex); } }