Hi,
i'm configure email and password in app.config like this :
and this is my code :
public partial class Form1 : Form
{
string URI;
LoginData ld = new LoginData();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void submit_Click(object sender, EventArgs e)
{
URI = string.Concat(host.Text, api.Text);//textBox2.Text + textBox1.Text;
GetLogin();
}
#region Methods
private async void GetLogin()
{
using (var client = new HttpClient())
{
var login = new LoginData() ConfigurationSettings.AppSettings{ Email ="email", Password = "password" };
var response = await client.PostAsJsonAsync(URI, login);
if (response.IsSuccessStatusCode)
{
var productJsonString = await response.Content.ReadAsStringAsync();
body.Text = productJsonString;
}
}
}
}
#endregion
public class LoginData
{
public string Email { get; set; }
public string Password { get; set; }
}
}
But this is not working.give me a correct code.
{
string URI;
LoginData ld = new LoginData();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void submit_Click(object sender, EventArgs e)
{
URI = string.Concat(host.Text, api.Text);//textBox2.Text + textBox1.Text;
GetLogin();
}
#region Methods
private async void GetLogin()
{
using (var client = new HttpClient())
{
var login = new LoginData() ConfigurationSettings.AppSettings{ Email ="email", Password = "password" };
var response = await client.PostAsJsonAsync(URI, login);
if (response.IsSuccessStatusCode)
{
var productJsonString = await response.Content.ReadAsStringAsync();
body.Text = productJsonString;
}
}
}
}
#endregion
public class LoginData
{
public string Email { get; set; }
public string Password { get; set; }
}
}
But this is not working.give me a correct code.
Thank you.

Shashank PatilPosted Sep 10, 2015, 12:48 AM
using System.Configuration;
NameValueCollection appSettings = ConfigurationManager.AppSettings;
string email = appSettings["email"];
string password = appSettings["password"];
Raja TPosted Sep 10, 2015, 12:43 AM