public async Task processAuthentication() { var json = await( authEntity.getBaseUrl() + "/v1/authenticate" ).PostUrlEncodedAsync( new { username = authEntity.getUsername(), key = authEntity.getPassword() } ).ReceiveString(); HttpRequestResponse = json; }
static async Task <String> authenticate() { HttpClient client = new HttpClient(); var values = new Dictionary <string, string> { { "username", authEntity.getUsername() }, { "key", authEntity.getPassword() } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync((authEntity.getBaseUrl() + "/v1/authenticate"), content); var json = await response.Content.ReadAsStringAsync(); return(json); }
public void Authenticate() { WebRequestUtil wrUtil = new WebRequestUtil(new AuthorizationEntity("", "", "")); Dictionary <string, string> post_data = new Dictionary <string, string>(); post_data.Add("username", authEntity.getUsername()); post_data.Add("key", authEntity.getPassword()); String url = (authEntity.getBaseUrl() + "/v1/authenticate"); webResponse = wrUtil.postRequest(url, post_data); /*String url = (authEntity.getBaseUrl() + "/v1/authenticate"); * WebRequest request = WebRequest.Create(url); * request.Method = "POST"; * request.ContentType = "application/x-www-form-urlencoded"; * * // manual concat credentials * //String post_data = "username="******"&key=" + authEntity.getPassword(); * * // using string builder * StringBuilder formData = new StringBuilder(); * formData.AppendFormat("{0}={1}", "username", authEntity.getUsername()); * formData.AppendFormat("&{0}={1}", "key", authEntity.getPassword()); * String post_data = formData.ToString(); * * Stream stream = request.GetRequestStream(); * byte[] postArray = Encoding.ASCII.GetBytes(post_data); * stream.Write(postArray, 0, postArray.Length); * stream.Close(); * * StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); * string Result = sr.ReadToEnd(); * * webResponse = Result.ToString();*/ }