Hi,
I’m new developing with ElectricImp.
I try to make an simple App with visual studio c# for windows phone 8.0. This App simply send a request with led=“string” with an Http Request using POST method.
From an HTML page all function good, but when I try with this App, the agent does not seem to get anything.
The Visual C # code works for other sites and I can not understand why it does not work with the agent of electricimp.
I know this is not a site for visual c # developer but maybe someone already solved.
Thank you
Carlo
This is the agent code :
`function requestHandler(request, response) {
foreach(k, v in request.query) {
server.log(k +" = " + v);
}
try {
// check if the user sent led as a query parameter
if (“led” in request.query) {
server.log("Ledstate: " + request.query.led);
local ledState = request.query.led;
// send "led" message to device, and send ledState as the data
device.send("led", ledState);
server.log("led =" + ledState);
}
//}
// send a response back saying everything was OK.
//server.log("led =" + ledState);
response.send(200, "OK * Ricevuto da App *");
} catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
// register the HTTP handler
http.onrequest(requestHandler);`
This is the Visual C# code
` private void Button_Click(object sender, RoutedEventArgs e)
{
string url = “https://agent.electricimp.com/XXXXXXXXXXX”;
Uri uri = new Uri(url, UriKind.Absolute);
StringBuilder postData = new StringBuilder();
postData.AppendFormat("{0}={1}", "led", HttpUtility.UrlEncode("string"));
WebClient client = default(WebClient);
client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();
client.UploadStringCompleted += client_UploadStringCompleted;
client.UploadProgressChanged += client_UploadProgressChanged;
client.UploadStringAsync(uri, "POST", postData.ToString());
}`