2024年3月21日发(作者:)

246 n(sr);

247 }

248

249 }

例3

1 /**

2 * 发送Http post请求

3 *

4 * @param xmlInfo

5 * json转化成的字符串

6 * @param URL

7 * 请求url

8 * @return 返回信息

9 */

10 public static String doHttpPost(String xmlInfo, String URL) {

11 n("发起的数据:" + xmlInfo);

12 byte[] xmlData = es();

13 InputStream instr = null;

14 rayOutputStream out = null;

15 try {

16 URL url = new URL(URL);

17 URLConnection urlCon = nnection();

18 utput(true);

19 nput(true);

20 Caches(false);

21 uestProperty("content-Type", "application/json");

22 uestProperty("charset", "utf-8");

23 uestProperty("Content-length",

24 f());

25 n(f());

26 DataOutputStream printout = new DataOutputStream(

27 putStream());

28 (xmlData);

29 ();

30 ();

31 instr = utStream();

32 byte[] bis = Array(instr);

33 String ResponseString = new String(bis, "UTF-8");

34 if ((ResponseString == null) || ("".equals(()))) {

35 n("返回空");

36 }

37 n("返回数据为:" + ResponseString);

38 return ResponseString;

39

40 } catch (Exception e) {

41 tackTrace();

42 return "0";

43 } finally {

44 try {

45 ();

46 ();

47

48 } catch (Exception ex) {

49 return "0";

50 }

51 }

52 }