80,351
社区成员
发帖
与我相关
我的任务
分享
package album.utill;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.content.Context;
import android.widget.Toast;
public class sendRequest {
private Context c;
private InputStream is;
private String result;
String type = "";
public sendRequest(String url,Context c,String type){
String httpUrl = url;
HttpGet httpRequest = new HttpGet(httpUrl);
HttpClient httpclient = new DefaultHttpClient();
this.c = c;
try {
HttpResponse res = httpclient.execute(httpRequest);
//Toast.makeText(c, "connected", Toast.LENGTH_LONG).show();
if (res.getStatusLine().getStatusCode() == 200) {
//Toast.makeText(c, "right", Toast.LENGTH_LONG).show();
InputStream is = res.getEntity().getContent();
if(is!=null){
if(type.equals("simple")){
String r = "";
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
r = br.readLine();
this.result = r;
Toast.makeText(c, r, Toast.LENGTH_LONG).show();
}
else{
//Toast.makeText(c, "object", Toast.LENGTH_LONG).show();
this.is = is;
}
}
} else {
Toast.makeText(c, "error", Toast.LENGTH_LONG).show();
//textI.setText("请求错误");
}
}
catch (Exception e) {
e.getStackTrace();
}
}
public InputStream getInputStream(){
return this.is;
}
public String getResult(){
Toast.makeText(this.c, "asd"+this.result, Toast.LENGTH_LONG).show();
return this.result;
}
}
package album.servlet;
import com.demo.android.album.userApplication;
import com.demo.hibernate.beans.UserList;
import album.utill.sendRequest;
import android.content.Context;
import android.widget.Toast;
public class addFriendServlet {
private boolean valid;
public addFriendServlet(Context c,String username){
String url1 = "http://113.55.43.123" +
":8080/AlbumOnline/addFriend";
userApplication ua = new userApplication();
ua = (userApplication)c.getApplicationContext();
UserList user = new UserList();
user = ua.getUser();
String uname = user.getUserName();
String url2 = "?userName="+uname;
String url3 = "&f_name="+username;
String url = url1+url2+url3;
sendRequest sr = new sendRequest(url,c,"simple");
String result;
result = sr.getResult();
Toast.makeText(c, "asdasd"+result, Toast.LENGTH_LONG);
if("yes".equals(result)){
this.valid = true;
}else{
Toast.makeText(c, "fail", Toast.LENGTH_LONG);
}
}
public boolean getResult(){
return this.valid;
}
}
红色的toast一致没有显示 后便也都出不来。。。到底哪儿错了 ?