C# POST/GET Windows 10

 

 

private
async
void post_Click(object sender, RoutedEventArgs e)

{


string url = “URL”;


HttpClient client = new
HttpClient();


HttpResponseMessage response = await client.GetAsync(url);


///var JsonString = await response.Content.ReadAsStringAsync();


string page_response = await response.Content.ReadAsStringAsync();


Debug.WriteLine(page_response);

}

 


private
async
void post_Click_1(object sender, RoutedEventArgs e)

{


///url…


string url = “URL”;


///creacion de las variables a subir


//IEnumerable<KeyValuePair<string, string>> query = new List<KeyValuePair<string, string>>()


//{


// new KeyValuePair<string, string>(“email”,”edgar@gmail.com”),


// new KeyValuePair<string, string>(“pass”,”moreno”),


// new KeyValuePair<string, string>(“tipoUsr”,”1″)


//};

 


var values = new
Dictionary<string,string>{

{“email”,“arturo@gmail.com”},

{“pass”,“flores”},

{“tipoUsr”,“0”}

};

 

 


/**


{ “email”,”arturo@gmail.com” },


{ “pass”,”flores” },


{ “tipoUsr “,”0”}

 


{ “email”,”edgar@gmail.com” },


{ “pass”,”moreno” },


{ “tipoUsr “,”1”}

 

 


{ “email”,”ramses@gmail.com” },


{ “pass”,”miramontes” },


{ “tipoUsr “,”0”}

 


{“email”: “ramses@gmail.com”, “pass”: “miramontes”, “tipoUsr”: “0”}

 

 


email:arturo@gmail.com

pass:flores

tipoUsr:0


*/

 


///creando contenido y agregandole las variables POST


HttpContent content = new
FormUrlEncodedContent(values);////estamos calando otras formas de crear variables


///creando el cliente que abrira la conexion


HttpClient client = new
HttpClient();


//////////En esta parte debe ir lo de Headers, solo que aun no sabemos como debe ser hecha… por lo tanto declaro:


/////////////////////////////////////////////ZONA DE DESARROLLO —->iNICIO


/// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));


/***

http://stackoverflow.com/questions/10679214/how-do-you-set-the-content-type-header-for-an-httpclient-request

***/


/////////////////////////////////////////////ZONA DE DESARROLLO —->fINAL


///agregando la respuesta a una variable del tipo que puede contenerla….


HttpResponseMessage response = await client.PostAsync(url, content);


///creando algo que se puede acceder mas tarde


string page_response = await response.Content.ReadAsStringAsync();


Debug.WriteLine(page_response);


Debug.WriteLine(response.Headers.ToString());

 

 

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s