免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Java發(fā)送HTTP的POST請求

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.net.HttpURLConnection;

import java.net.URL;

import java.util.Map;

import java.util.Map.Entry;

 

/**

 * @author yoUng

 * @description 發(fā)送http請求

 * @filename HttpUtil.java

 * @time 2011-6-15 下午05:26:36

 * @version 1.0

 */

public class HttpUtil {

 

public static String http(String url, Map<String, String> params) {

URL u = null;

HttpURLConnection con = null;

//構(gòu)建請求參數(shù)

StringBuffer sb = new StringBuffer();

if(params!=null){

for (Entry<String, String> e : params.entrySet()) {

sb.append(e.getKey());

sb.append("=");

sb.append(e.getValue());

sb.append("&");

}

sb.substring(0, sb.length() - 1);

}

System.out.println("send_url:"+url);

System.out.println("send_data:"+sb.toString());

//嘗試發(fā)送請求

try {

u = new URL(url);

con = (HttpURLConnection) u.openConnection();

con.setRequestMethod("POST");

con.setDoOutput(true);

con.setDoInput(true);

con.setUseCaches(false);

con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream(), "UTF-8");

osw.write(sb.toString());

osw.flush();

osw.close();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (con != null) {

con.disconnect();

}

}

 

//讀取返回內(nèi)容

StringBuffer buffer = new StringBuffer();

try {

BufferedReader br = new BufferedReader(new InputStreamReader(con

.getInputStream(), "UTF-8"));

String temp;

while ((temp = br.readLine()) != null) {

buffer.append(temp);

buffer.append("\n");

}

} catch (Exception e) {

e.printStackTrace();

}

 

return buffer.toString();

}

 

}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JAVA版微信支付V3-完全版
易寶Java版在線支付
JSP與樹型菜單
java反射
Java關(guān)于JSON數(shù)據(jù)格式轉(zhuǎn)換
解決Java中MD5加密utf-8格式時與其他語言不同的問題
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服