I face a strange problem, that i am not able to decode the data from http post message from my andriod .
we are sending data, - device + command as part of HTTP POST Header + Data
Android code
void sendSignal(String device, String cmd)
{
HttpParams httpParameters = new BasicHttpParams();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(“http://192.168.1.7:80”);
//HttpGet httpget = new HttpGet("http://192.168.1.3/?LED=Fowd+ device ");
HttpResponse response = null;
try
{
// Add your data
Log.d(“myapp”, “works till here. 2”);
//Execute HTTP Post Request
List nameValuePairs = new ArrayList(2);
nameValuePairs.add(new BasicNameValuePair(“devicename”, device));
nameValuePairs.add(new BasicNameValuePair(“command”, cmd));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d(“myapp”, "devicename " + device);
Log.d(“myapp”, "command " + cmd);
Log.d(“myapp”, "httppost " + httppost);
response = httpclient.execute(httppost);
Log.d(“myapp”, “works till here. 3”);
String responseBody = EntityUtils.toString(response.getEntity());
Log.d(“myapp”, "response " + responseBody);
} catch (ClientProtocolException e11) {
// TODO Auto-generated catch block
e11.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
}
}
but when we take the wifily webserver example, it receive the http post, but i am not able to extract the http post content…
Webserver example of wifily
void loop() {
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char type = client.read();
// if we’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (type == ‘\n’ && current_line_is_blank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();
// output the value of each analog input pin
for (int i = 0; i < 6; i++) {
client.print("analog input ");
client.print(i);
client.print(" is ");
client.print(analogRead(i));
client.println("
");
}
break;
}
if (type == ‘\n’) {
// we’re starting a new line
current_line_is_blank = true;
} else if (type != ‘\r’) {
// we’ve gotten a character on the current line
current_line_is_blank = false;
}
}
}
if i need to extract http Post data, from where we can read… appreciate the help on this , and also do have any sample code of parsing please share…