HI, as I am a beginner for Android.
Now I am trying to do a test application for sending HTTP Request.
But I find that my coding is not work.
So I hope someone can give me some ideas on it.
The following is my code:
package com.example.helloandroid;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = new HttpPost("www.yahoo.com.hk");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
String str = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(str);
//setContentView(R.layout.main);
}
}
Now I am trying to do a test application for sending HTTP Request.
But I find that my coding is not work.
So I hope someone can give me some ideas on it.
The following is my code:
package com.example.helloandroid;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
try
{
HttpClient hc = new DefaultHttpClient();
HttpPost post = new HttpPost("www.yahoo.com.hk");
HttpResponse rp = hc.execute(post);
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
String str = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(str);
//setContentView(R.layout.main);
}
}
ON'T FORGET TO ADD "HTTP://"!