package com.mobileclient.util;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
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.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import com.mobileclient.activity.photoListActivity;
import com.mobileclient.app.Declare;
public class HttpUtil {
// 基础URL
public static final String BASE_URL = "http://192.168.1.103:8080/JavaWebProject/";
public static final String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/mobileclient";
public static final String Cach_Dir = Declare.context.getCacheDir().getAbsolutePath();
// 获得Get请求对象request
public static HttpGet getHttpGet(String url) {
HttpGet request = new HttpGet(url);
return request;
}
// 获得Post请求对象request
public static HttpPost getHttpPost(String url) {
HttpPost request = new HttpPost(url);
return request;
}
// 根据请求获得响应对象response
public static HttpResponse getHttpResponse(HttpGet request)
throws ClientProtocolException, IOException {
HttpResponse response = new DefaultHttpClient().execute(request);
return response;
}
// 根据请求获得响应对象response
public static HttpResponse getHttpResponse(HttpPost request)
throws ClientProtocolException, IOException {
HttpResponse response = new DefaultHttpClient().execute(request);
return response;
}
// 发送Post请求,获得响应查询结果
public static String queryStringForPost(String url) {
// 根据url获得HttpPost对象
HttpPost request = HttpUtil.getHttpPost(url);
String result = null;
try {
// 获得响应对象
HttpResponse response = HttpUtil.getHttpResponse(request);
// 判断是否请求成功
if (response.getStatusLine().getStatusCode() == 200) {
// 获得响应
result = EntityUtils.toString(response.getEntity());
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
result = "网络异常!";
return result;
} catch (IOException e) {
e.printStackTrace();
result = "网络异常!";
return result;
}
return null;
}
// 获得响应查询结果
public static String queryStringForPost(HttpPost request) {
String result = null;
try {
// 获得响应对象
HttpResponse response = HttpUtil.getHttpResponse(request);
// 判断是否请求成功
if (response.getStatusLine().getStatusCode() == 200) {
// 获得响应
result = EntityUtils.toString(response.getEntity());
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
result = "网络异常!";
return result;
} catch (IOException e) {
e.printStackTrace();
result = "网络异常!";
return result;
}
return null;
}
// 发送Get请求,获得响应查询结果
public static String queryStringForGet(String url) {
// 获得HttpGet对象
HttpGet request = HttpUtil.getHttpGet(url);
String result = null;
try {
// 获得响应对象
HttpResponse response = HttpUtil.getHttpResponse(request);
// 判断是否请求成功
if (response.getStatusLine().getStatusCode() == 200) {
// 获得响应
result = EntityUtils.toString(response.getEntity());
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
result = "网络异常!";
return result;
} catch (IOException e) {
e.printStackTrace();
result = "网络异常!";
return result;
}
return null;
}
public static boolean sendXML(String path, String xml) throws Exception {
byte[] data = xml.getBytes();
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(5 * 1000);
conn.setDoOutput(true);// 如果通过post提交数据,必须设置允许对外输出数据
conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(data);
outStream.flush();
outStream.close();
if (conn.getResponseCode() == 200) {
return true;
}
return false;
}
public static byte[] sendGetRequest(String path,
Map<String, String> params, String enc) throws Exception {
StringBuilder sb = new StringBuilder(path);
sb.append('?');
// ?method=save&title=435435435&timelength=89&
for (Map.Entry<String, String> entry : params.entrySet()) {
sb.append(entry.getKey()).append('=')
.append(URLEncoder.encode(entry.getValue(), enc))
.append('&');
}
sb.deleteCharAt(sb.length() - 1);
URL url = new URL(sb.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
if (conn.getResponseCode() == 200) {
return readStream(conn.getInputStream());
}
return null;
}
public static boolean sendPostRequest(String path,
Map<String, String> params, String enc) throws Exception {
// title=dsfdsf&timelength=23&method=save
StringBuilder sb = new StringBuilder();
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
sb.append(entry.getKey()).append('=')
.append(URLEncoder.encode(entry.getValue(), enc))
.append('&');
}
sb.deleteCharAt(sb.length() - 1);
}
byte[] entitydata = sb.toString().getBytes();// 得到实体的二进制数据
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(5 * 1000);
conn.setDoOutput(true);// 如果通过post提交数据,必须设置允许对外输出数据
// Content-Type: application/x-www-form-urlencoded
// Content-Length: 38
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length",
String.valueOf(entitydata.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(entitydata);
outStream.flush();
outStream.close();
if (conn.getResponseCode() == 200) {
return true;
}
return false;
}
public static byte[] SendPostRequest(String path,
Map<String, String> params, String enc) throws Exception {
// title=dsfdsf&timelength=23&method=save
StringBuilder sb = new StringBuilder();
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
sb.append(entry.getKey()).append('=')
.append(URLEncoder.encode(entry.getValue(), enc))
.append('&');
}
sb.deleteCharAt(sb.length() - 1);
}
byte[] entitydata = sb.toString().getBytes();// 得到实体的二进制数据
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(5 * 1000);
conn.setDoOutput(true);// 如果通过post提交数据,必须设置允许对外输�
没有合适的资源?快使用搜索试试~ 我知道了~
安卓Android病人住院信息管理系统
共472个文件
java:147个
xml:89个
gif:85个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 87 浏览量
2023-12-31
23:54:48
上传
评论
收藏 17.41MB ZIP 举报
温馨提示
科室: 科室编号,科室名称,成立日期,负责人 医生: 医生工号,登录密码,所在科室,姓名,性别,身份证号,医生照片,出生日期,联系电话,毕业学校,工作经验,备注 病人: 病人id,姓名,性别,出生日期,身份证号,籍贯,联系电话,联系地址,病历历史 住院: 住院id,病人,年龄,住院日期,入住天数,床位号,负责医生,备注信息 药品: 药品id,药品名称,药品单位,药品单价 治疗: 治疗id,治疗名称,病人,诊断情况,治疗记录,治疗结果,主治医生,治疗开始时间,疗程时间 用药: 用药id,治疗名称,所用药品,用药数量,药品费用,用药时间
资源推荐
资源详情
资源评论
收起资源包目录
安卓Android病人住院信息管理系统 (472个子文件)
.classpath 3KB
.classpath 364B
org.eclipse.wst.jsdt.ui.superType.container 49B
index.css 2KB
style.css 2KB
desk.css 841B
Thumbs.db 54KB
Thumbs.db 26KB
logo.gif 81KB
login_03.gif 30KB
login_08.gif 25KB
login_03 - 副本.gif 19KB
login_05.gif 7KB
login_07.gif 5KB
main_30.gif 3KB
main_40.gif 3KB
main_03.gif 3KB
main_32.gif 2KB
main_04.gif 2KB
main_29.gif 2KB
main_22.gif 2KB
main_48.gif 2KB
main_47.gif 2KB
login_06.gif 2KB
error_b.gif 1KB
main_20.gif 1KB
main_18.gif 1KB
main_12.gif 1KB
main_11.gif 1KB
main_14.gif 1KB
main_16.gif 1KB
tab_17.gif 924B
tab_17.gif 924B
main_58.gif 804B
tab_20.gif 770B
tab_20.gif 770B
tab_07.gif 752B
tab_07.gif 752B
back.gif 749B
back.gif 749B
next.gif 745B
next.gif 745B
last.gif 741B
last.gif 741B
go.gif 736B
first.gif 736B
go.gif 736B
first.gif 736B
tab_18.gif 715B
tab_18.gif 715B
main_07.gif 701B
tab_03.gif 699B
tab_03.gif 699B
main_37.gif 661B
main_05.gif 640B
tb.gif 585B
tb.gif 585B
main_31.gif 552B
tab_19.gif 420B
tab_19.gif 420B
dl.gif 377B
tab_05.gif 375B
tab_05.gif 375B
11.gif 341B
11.gif 341B
33.gif 337B
33.gif 337B
main_21.gif 317B
main_34.gif 292B
bg.gif 273B
22.gif 215B
22.gif 215B
main_36.gif 203B
main_55_1.gif 201B
main_55.gif 201B
edt.gif 197B
edt.gif 197B
bg.gif 160B
del.gif 145B
del.gif 145B
left.gif 124B
tab_15.gif 112B
tab_15.gif 112B
tab_12.gif 111B
tab_12.gif 111B
main_59.gif 93B
main_62.gif 92B
main_52.gif 79B
main_51.gif 77B
main_45.gif 52B
main_41.gif 52B
main_39.gif 52B
main_61.gif 37B
.gitattributes 91B
tab.html 23KB
middel.html 2KB
down.html 879B
center.html 715B
right.html 0B
spring.jar 2.81MB
共 472 条
- 1
- 2
- 3
- 4
- 5
资源评论
软件源码
- 粉丝: 778
- 资源: 108
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功