HttpResponse from Arduino ethernet to Android Application

Hello guys,
I want to do a project that needs communication between Android application and Arduino Ethernet board in both ways. I was successful to send HttpRequest from Android phone to Arduino board, but when I want to send back response as a result of the HttpRequest from Arduino board to the same Android phone, I am not able to receive anything. Actually, I am trying to handle a simple authentication page which send username and password to Arduino and Arduino send back “authentication OK” to android phone. BTW, if there is any better method to provides me this communication, I'd appreciate to offer with examples;)

Android Code:

public void onClick(View v) {

		if (v == btn) {

			HttpClient httpclient = new DefaultHttpClient();
			HttpGet httpget = new HttpGet("http://192.168.1.113/signIn/?Pa1="
					+ txtUserName.getText().toString() + "&Pa2="
					+ txtPassword.getText().toString());
			try {
				httpclient.execute(httpget);
				HttpResponse response = httpclient.execute(httpget);
				this.request(response, txtResult);
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
			} catch (IOException e) {
				// TODO Auto-generated catch block
			}
		}
	}

	public void request(HttpResponse response, TextView tx) {
		
		try {
			InputStream in = response.getEntity().getContent();

			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			StringBuilder str = new StringBuilder();
			String line = null;
			while ((line = reader.readLine()) != null) {
				str.append(line + "\n");
			}
			in.close();
			tx.setText(str);
		} catch (Exception ex) {
			tx.setText("Failed!");
		}

	}

Arduino Code:

if (strcmp(buffer, "signIn") == 0){

	if(finder.getString("", "&", buffer1, sizeof(buffer1))){
                Serial.println(buffer1);
                if (strcmp(buffer1, "?Pa1=admin") == 0){
                                            
                     if(finder.getString("", " HTTP", buffer2, sizeof(buffer2))){
                          Serial.println(buffer2);
                          if (strcmp(buffer2, "Pa2=1234") == 0){
                                                  
                          //this is the part that I try to send back response to android phone  
                          client.println("Authenticate OK"); 
                                                  
                          }
                         }
                        }   
                       }
                      }
	             }

I voted. Beats me what you want the poll results for, but, I voted.

Firstly test from an ordinary web browser first, if you use Firefox you can install Firebug and debug the HTTP traffic nicely, then once that's working progress to Android.

Secondly are you sending a valid "Content-Type:" header - can't see enough of your code to know - also have you started from a working web-serving example piece of code in the first place (ie has your code ever worked?)

I've used examples from the EtherShield library OK with Android browser, and also from in an Android App, so this shouldn't be too hard once you've worked out what's missing...

Actually thinking back to your description of what you are trying to achieve, I've been looking into providing secure communications from an Arduino Ethernet board (SSL not being practical on an Arduino alas).

I suspect its a common wish/requirement that your network-enabled Arduino can't be hacked into and something a bit more secure than passwords sent in the clear would be useful.

I've implemented some of the basic functionality to provide this (as described in "Practical Cryptography", Fergusson/Schneier) but using XXTEA as the block encryption algorithm rather than AES - the idea being to authenticate communication over Web or TCP with a shared secret key.

I'm still thinking about how this fits in to the wider picture of networked devices and web access - perhaps a browser-plugin to handle the browser side of the authentication/encryption/key-storage.

The real impetus for this is that people are increasing going to be controlling devices in their home remotely and there are genuine risks if the communications aren't properly secured (such as with SSL). Small 8-bit microcontrollers are not up to processing heavyweight public-key encryption so there is a need for something that can run on an Arduino or whatever and provide that protection against remote hacking and war-driving.

Sorry, digressing off topic!

Thanks for the replies,

I test this code with web, I can see the content and it works perfectly. But when I want to communicate with android application I encounter the problem I said. I sent below code as the response for the request, but when sending, Arduino creates problems. So, I don't know what to do? Should I send any special code as a response (Content-Type:) to Arduino to be able to receive data (text data)?

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("Authenticate OK");

You are saying the content is HTML when it isn't, I presume on the Android side that generates an error. text/plain is the right content type IIRC