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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

httpclient調(diào)接口post出現(xiàn)無響應(yīng)400

httpclient調(diào)接口post出現(xiàn)無響應(yīng)400

qq_fly_5 2020-01-07 15:17:13
???String?uri=url+bundle.getString("postCookie.uri"); ????//生成httpclient對象 ???//?CloseableHttpClient?httpClient?=?HttpClientBuilder.create().build(); ???DefaultHttpClient?httpClient?=?new?DefaultHttpClient(); ????//創(chuàng)建post請求 ????HttpPost?httpPost=new?HttpPost(uri); ????//使用json入?yún)?,入?yún)⑹侵形臅r不行。 ????JSONObject?param=new?JSONObject(); ????param.put("name","qinzhenxia"); ????param.put("age","28"); ????//設(shè)置請求頭header ????httpPost.setHeader("Content-Type","application/json;charset=gbk"); ????//傳入?yún)?shù) ????StringEntity?entity=new?StringEntity(param.toString(),"gbk"); ????httpPost.setEntity(entity); ????//聲明一個client對象,用來進行方法的執(zhí)行,并設(shè)置cookies信息 ????CloseableHttpClient?httpclient?=?HttpClients.custom().setDefaultCookieStore(this.store).build(); ????//執(zhí)行請求并接收返回結(jié)果 ????HttpResponse?httpResponse?=?httpClient.execute(httpPost); ????String?result=EntityUtils.toString(httpResponse.getEntity()); ????//判斷返回code值 ????int?statuscode=httpResponse.getStatusLine().getStatusCode(); ????if?(statuscode==200){ ????????System.out.println(result); ????}?else?{ ????????System.out.println("訪問/postwithcookiesandjsontwo接口失敗"); ????} ????//獲取返回結(jié)果并轉(zhuǎn)換為jsonobject格式,然后獲取某個具體的值通過斷言判斷 ????JSONObject?resultjson=new?JSONObject(result); ????String?msg?=resultjson.getString("msg"); ????//判斷msg等于success ????Assert.assertEquals(msg,"success"); ????JSONObject?p2pdata=resultjson.getJSONObject("p2pdata"); ????String?address=p2pdata.getString("address"); ????Assert.assertEquals(address,"北三環(huán)"); ????System.out.println(address); }訪問/postwithcookiesandjsontwo接口失敗
查看完整描述

2 回答

?
慕移動7568944

TA貢獻1條經(jīng)驗 獲得超0個贊

//DefaultHttpClient httpClient = new DefaultHttpClient();
上面這句注釋掉

HttpResponse httpResponse = httpClient.execute(httpPost);
httpClient改成httpclient,即
HttpResponse httpResponse = httpclient.execute(httpPost);

?

查看完整回答
反對 回復(fù) 2021-02-03
?
安浪創(chuàng)想

TA貢獻81條經(jīng)驗 獲得超23個贊

你用http 測試工具訪問正常不正常再檢查代碼。也就是服務(wù)端接口正常了,才能說明你的客戶端代碼有問題。

查看完整回答
反對 回復(fù) 2020-01-28
  • 2 回答
  • 0 關(guān)注
  • 1769 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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