通过
http
传送接收数据
通过http传输文件一般分为传送和接收,简单说来就是你向别人发送文件和接收别人传给你的文件。下面大致说一下这两种情况。
1、 向别人发送文件
目前觉得简单的方式还是通过http以流的形式发送文件,下面给出一部分代码:
/** */
/**
* 通过http以流形式传递参数
*
* @param url
* 请求地址
* @param xmlValue
* xml字符串
* @return true post成功,post失败
*/
public static boolean post(String sUrl, String xmlValue) ... {
try ...{
if (sUrl == null || sUrl.trim().equals("")) ...{
throw new Exception("发送指令时目标URL地址无效");
}
// 声明hc变量
URL url = new URL(sUrl);
HttpURLConnection hc = (HttpURLConnection) url.openConnection();
* 通过http以流形式传递参数
*
* @param url
* 请求地址
* @param xmlValue
* xml字符串
* @return true post成功,post失败
*/
public static boolean post(String sUrl, String xmlValue) ... {
try ...{
if (sUrl == null || sUrl.trim().equals("")) ...{
throw new Exception("发送指令时目标URL地址无效");
}
// 声明hc变量
URL url = new URL(sUrl);
HttpURLConnection hc = (HttpURLConnection) url.openConnection();