[android-developers] Read Response from PHP server

2011-01-18 Thread Atif Musaddaq
Hi, Guys

Facing a small problem, I want to know two things, Either i am going in the
right direction ? Second why i have these two syntax error, See below the
exact line.
1. *Syntax error on token ;, { expected after this token*
*2. **Error: Syntax error, insert } to complete ClassBody*
*
*
*Note I am beginner plz donot mind if i am doing some foolish mistake :-)
Thanks in advance*

here is my simple PHP code.
**
?php
echo param1 value: .$_POST['parameterName1'].\n;
echo param2 value: .$_POST['parameterName2'].\n;
echo Your post was successfully sent;
?
**
Now here come my Java code

//all Required imports and package

public class http_client extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

}
HttpPost httppost;

HttpClient httpclient;

// List with arameters and their values
ListNameValuePair nameValuePairs;

String serverResponsePhrase;
int serverStatusCode;
String bytesSent; * Syntax error on token ;, { expected after
this token*

httppost = new HttpPost(serverURL);
httpclient = new DefaultHttpClient();
nameValuePairs = new ArrayListNameValuePair(2);

// Adding parameters to send to the HTTP server.
nameValuePairs.add(new BasicNameValuePair(parameterName1, value1));
nameValuePairs.add(new BasicNameValuePair(parameterName2, value2));

// Send POST message  with given parameters to the HTTP server.
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);

int current = 0;
while((current = bis.read()) != -1)
{
baf.append((byte)current);
}

bytesSent = new String(baf.toByteArray());

// Response from the server
serverResponsePhrase = response.getStatusLine().getReasonPhrase();
serverStatusCode = response.getStatusLine().getStatusCode();
// for receiving response from the server
Toast.makeText(getBaseContext(),
 bytesSent,
 Toast.LENGTH_SHORT).show();


}
catch (Exception e) {
// Exception handling
}

} *  Error: Syntax error, insert } to complete ClassBody*

-- 
Atif

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Read Response from PHP server

2011-01-18 Thread TreKing
On Tue, Jan 18, 2011 at 1:13 PM, Atif Musaddaq atif.musad...@gmail.comwrote:

 setContentView(R.layout.main);

 } * THIS WOULD BE A PROBLEM*
 HttpPost httppost;


-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Read Response from PHP server

2011-01-18 Thread 20plus10 30
Hi

I can see anywhere that you have defin your serverURL !!! to your php server
URL!

/Maali


2011/1/18 Atif Musaddaq atif.musad...@gmail.com

 Hi, Guys

 Facing a small problem, I want to know two things, Either i am going in the
 right direction ? Second why i have these two syntax error, See below the
 exact line.
 1. *Syntax error on token ;, { expected after this token*
 *2. **Error: Syntax error, insert } to complete ClassBody*
 *
 *
 *Note I am beginner plz donot mind if i am doing some foolish mistake :-)
 Thanks in advance*

 here is my simple PHP code.
 **
 ?php
 echo param1 value: .$_POST['parameterName1'].\n;
 echo param2 value: .$_POST['parameterName2'].\n;
 echo Your post was successfully sent;
 ?
 **
 Now here come my Java code

 //all Required imports and package

 public class http_client extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 }
 HttpPost httppost;

 HttpClient httpclient;

 // List with arameters and their values
 ListNameValuePair nameValuePairs;

 String serverResponsePhrase;
 int serverStatusCode;
 String bytesSent; * Syntax error on token ;, { expected after
 this token*

 httppost = new HttpPost(serverURL);
 httpclient = new DefaultHttpClient();
 nameValuePairs = new ArrayListNameValuePair(2);

 // Adding parameters to send to the HTTP server.
 nameValuePairs.add(new BasicNameValuePair(parameterName1, value1));
 nameValuePairs.add(new BasicNameValuePair(parameterName2, value2));

 // Send POST message  with given parameters to the HTTP server.
 try {
 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

 HttpResponse response = httpclient.execute(httppost);

 InputStream is = response.getEntity().getContent();
 BufferedInputStream bis = new BufferedInputStream(is);
 ByteArrayBuffer baf = new ByteArrayBuffer(20);

 int current = 0;
 while((current = bis.read()) != -1)
 {
 baf.append((byte)current);
 }

 bytesSent = new String(baf.toByteArray());

 // Response from the server
 serverResponsePhrase = response.getStatusLine().getReasonPhrase();
 serverStatusCode = response.getStatusLine().getStatusCode();
 // for receiving response from the server
 Toast.makeText(getBaseContext(),
  bytesSent,
  Toast.LENGTH_SHORT).show();


 }
 catch (Exception e) {
 // Exception handling
 }

 } *  Error: Syntax error, insert } to complete ClassBody*

 --
 Atif

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Read Response from PHP server

2011-01-18 Thread Frank Weiss
You may have already figured this out.

String bytesSent;

is a valid field definition, but the following line:

httppost = new HttpPost(serverURL);

is a statement and belongs in a method or initialized block.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en