我的意思是,我想要一个HTTP请求发送到我的服务器,如:
What i mean is that i want to send an http request to my server like:
HTTP:?//blahblah.blah/index.php 命令=使
在安卓
您可以不喜欢它:
HTTP POST:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://blahblah.blah/index.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("command", "make"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
HTTP GET
HttpResponse response = null;
try {
// Create http client object to send request to server
HttpClient client = new DefaultHttpClient();
// Create URL string
String URL = "http://blahblah.blah/index.php?command=make";
// Create Request to server and get response
HttpGet httpget= new HttpGet();
httpget.setURI(new URI(URL));
response = client.execute(httpget);
} catch (URISyntaxException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}