第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

java 測(cè)試post請(qǐng)求 在body里面?zhèn)鬟f參數(shù)怎么設(shè)置,怎么接收

java 測(cè)試post請(qǐng)求 在body里面?zhèn)鬟f參數(shù)怎么設(shè)置,怎么接收

BIG陽(yáng) 2019-03-01 11:00:18
public String post(String strURL,String params) { System.out.println(strURL); System.out.println(params); try { URL url = new URL(strURL);//?創(chuàng)建連接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST");//?設(shè)置請(qǐng)求方式?? connection.setRequestProperty("Accept","application/json");//?設(shè)置接收數(shù)據(jù)的格式?? connection.setRequestProperty("Content-Type","application/json");//?設(shè)置發(fā)送數(shù)據(jù)的格式?? connection.connect(); OutputStreamWriter out = new OutputStreamWriter( connection.getOutputStream(),"UTF-8");// utf-8編碼?? out.append(params); out.flush(); out.close(); //?讀取響應(yīng)?? int length = (int) connection.getContentLength();//?獲取長(zhǎng)度?? InputStream is = connection.getInputStream(); if (length != -1){ byte[] data = new byte[length]; byte[] temp = new byte[512]; int readLen = 0; int destPos = 0; while ((readLen = is.read(temp)) > 0){ System.arraycopy(temp, 0, data, destPos, readLen); destPos += readLen; } String result = new String(data, "UTF-8"); System.out.println(result); return result; } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return "error"; } @RequestMapping(value="/text", method = RequestMethod.POST) @ResponseBody public String text(HttpServletRequest request,HttpServletResponse response,@RequestBody String t){ System.out.println(t); return "DetailedRules"; }
查看完整描述

3 回答

?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

你可以用Paw或者Insomnia或者ARC來(lái)測(cè)試,不用寫(xiě)代碼啦

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
慕田峪9158850

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個(gè)贊

conn.setParam設(shè)置參數(shù)值。。。下個(gè)fiddler,調(diào)試快

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果只是測(cè)試接口,chorme里面下個(gè)postman測(cè)試就好了

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 3 回答
  • 0 關(guān)注
  • 10146 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)