2024 04 06 20 25 25 netduino is dead   Buscar con Google y 5 páginas más   Personal  Microsoft​ Edge

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.
allDone.WaitOne();

}
catch (Exception ex) {
Console.Write(ex.Message);
}

}

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);
postStream.Close();
allDone.Set();
}

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

Deja un comentario

Este sitio utiliza Akismet para reducir el spam. Conoce cómo se procesan los datos de tus comentarios.

La FRASE DEL MES

«Cualquier tecnología suficientemente avanzada es indistinguible de la magia.»

~ Arthur C. Clarke