Post 发送表单
private static void Postfrom(final String url, final Map<String, String> param, final Handler handler, final int code) {
new Thread() {
@Override
public void run() {
Log.e("POST", url);
String databack = HttpUrls.submitPostData(url, param, null);
Log.e(TAG, "param: " + param);
if (databack.equals("-1")) {
return;
}
Log.e(TAG, "返回值为" + databack);
if (handler != null) {
Message msg = Message.obtain();
if (code != 0) {
msg.what = code;
} else {
msg.what = COMM.OK;
}
msg.obj = databack;
handler.sendMessage(msg);
}
}
}.start();
使用get发送请求
private static void get(final String url, final Handler handler) {
new Thread() {
@Override
public void run() {
try {
String databack3 = HttpUrls.Get(url);
if ("404".equals(databack3)) {
System.out.println("链接失败utl" + url);
return;
}
System.out.println("链接成功返回数据为" + databack3);
System.out.println("链接utl" + url);
Message msg = new Message();
msg.what = MsgNum.OK;
Bundle bundle = new Bundle();
bundle.putString(MsgNum.NETWORKDATA, databack3);
msg.setData(bundle);
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}