Hi,it's my first post and i know it's a good place to share questions
and get answers.I want to make a webservice to read datas from
website.And the first step is to get an String returns by the
site.Here is my code,and i don't know why i can't get the String str
in which XML contains.
Thank you very much.
package com.yancaidaxia.ExchangeRate;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ExchangeRate extends Activity {
private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;
private static String str;
private static final String SERVER_URL="http://www.webxml.com.cn/
WebServices/ExchangeRateWebService.asmx/getExchangeRate?
theType=A"; //the site from which i get datas
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView)findViewById(R.id.welcome);
TextView tv2 =(TextView)findViewById(R.id.content);
String temp1 ="";
try{
HttpGet request = new HttpGet(SERVER_URL);
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse = client.execute(request);
temp1 = EntityUtils.toString(httpResponse.getEntity());//xml
datas in string form supposed to be contained in temp1.
str=temp1;
Log.e("response", temp1);
}catch(ClientProtocolException e){
Log.e("request error",e.getMessage());
} catch(IOException e){
Log.e("requset error",e.getMessage());
}
tv1.setText(str);//i want to see the xml datas in string form
but nothing is shown.Why?
tv2.setText("bye");
}
}