hi here i am sending the simple post method code
which connect to the server and read response
you can use http get in place of post method
may be this will help you
code example:
private void connectandgetresponse(final String arg_emailsStr)
{
Runnable ssr = new Runnable()
{
public void run()
{
String servResponse = "";
// to send arguments if required
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("arg1", Uri.encode(arg1value)));
nvps.add(new BasicNameValuePair("arg2", Uri.encode(arg2value)));
nvps.add(new BasicNameValuePair("arg3", Uri.encode(arg3Value))); ///
as many as wanted.....
// connect to server and get response from server ....
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("URL to connect");
try
{
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpost);
HttpEntity my_entity = response.getEntity();
if(null != my_entity)
{
InputStream input_Stream = my_entity.getContent();
int len = (int)my_entity.getContentLength();
if(len > 0)
{
Log.i("Length of content..","["+len+"]");
byte[] byteresp = new byte[len];
int st_pos = 0;
int req_sz = len;
int bytes_toRead = len;
int read_cnt = 0;
while(read_cnt < bytes_toRead)
{
int read_now = 0;
if(null != input_Stream)
{
read_now = input_Stream.read(byteresp,st_pos,req_sz);
}
if(-1 == read_now)
{
break;
}
read_cnt += read_now;
st_pos += read_now;
req_sz = bytes_toRead - read_cnt;
}
servResponse= new String(byteresp);
Log.i(getClass().getSimpleName(),"Response = ["+servResponse+"]");
}
else
{
Log.i(getClass().getSimpleName(), "No response.....");
}
}
else
{
Log.i(getClass().getSimpleName()," my_entity = NULL ");
}
}
catch (Exception e2)
{
e2.printStackTrace();
}
}
};
new Thread(ssr).start();
}
On Sat, Aug 29, 2009 at 6:11 PM, ragavendran s <[email protected]>wrote:
>
> how to read values from the server using Http GET method....
>
> whenever i m passing the url to the server it returns same url in the
> textview
>
> i think i commited mistake in http connection using GET method..would u tel
> me pls how it is....?..
>
> pls.......
>
>
>
> with regards,
> Raghav.S
>
> >
>
--
Dilli Rao. M
Software Developer
www.arijasoft.com
- a pioneer in Mobile App Development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---