Envio http post a url’s desde netduino

Un ejemplo de  código para enviar  request   desde Netduino a url usando post:

private static string pMessage;
public static ManualResetEvent allDone = new ManualResetEvent(false);

private void Form1_Load(object sender, EventArgs e) {
try {

//string serviceURL = “http://localhost:52976/SL2Astoria_Web/WebDataService.svc/Products/”;
string serviceURL = “http://localhost:52895/Service1.asmx/Service1”;

pMessage = “{” + Environment.NewLine;
pMessage += “ProductName=\”zone\”” + Environment.NewLine;
pMessage += “}” + Environment.NewLine;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceURL);
request.ContentType = “application/json”;
request.UserAgent = “Fiddler”;
//request.ContentType = “application/x-www-form-urlencoded”;
request.Method = “POST”;
request.BeginGetRequestStream(new AsyncCallback(ReadCallback), request);

// Keep the main thread from continuing while the asynchronous
// operation completes. A real world application
// could do something useful such as updating its user interface.

catch (Exception ex) {


private static void ReadCallback(IAsyncResult asynchronousResult) {
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation.
Stream postStream = request.EndGetRequestStream(asynchronousResult);

string postData = pMessage;

// Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);

fuente original :http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/c7854122-b61c-4f2c-aa44-831bf1d27af1/

Esta entrada fue publicada en Netduino.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.