xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 4KB
    文件類型: .java
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-08
  • 語言: Java
  • 標(biāo)簽: java調(diào)用??

資源簡介

java調(diào)用HTTP接口(Get請(qǐng)求和Post請(qǐng)求)

資源截圖

代碼片段和文件信息

package?com.company;

import?java.io.*;
import?java.net.HttpURLConnection;
import?java.net.URL;

/**
?*?功能簡述:
?*
?*?@author?caidingnu
?*?@create?2019/03/27?13:46
?*?@since?1.0.0
?*/
public?class?HTTP_Request?{
????private?static?void?httpURLGETCase()?{
????????String?methodUrl?=?“http://127.0.0.1:8099/select_by_id?userid=1“;
????????HttpURLConnection?connection?=?null;
????????BufferedReader?reader?=?null;
????????String?line?=?null;
????????try?{
????????????URL?url?=?new?URL(methodUrl);
????????????connection?=?(HttpURLConnection)?url.openConnection();//?根據(jù)URL生成HttpURLConnection
????????????connection.setRequestMethod(“GET“);//?默認(rèn)GET請(qǐng)求
????????????connection.connect();//?建立TCP連接
????????????if?(connection.getResponseCode()?==?HttpURLConnection.HTTP_OK)?{
????????????????reader?=?new?BufferedReader(new?InputStreamReader(connection.getInputStream()?“UTF-8“));//?發(fā)送http請(qǐng)求
????????????????StringBuilder?result?=?new?StringBuilder();
????????????????//?循環(huán)讀取流
????????????????while?((line?=?reader.readLine())?!=?null)?{
????????????????????result.append(line).append(System.getProperty(“l(fā)ine.separator“));//?“\n“
????????????????}
????????????????System.out.println(result.toString());
????????????}
????????}?catch?(IOException?e)?{
????????????e.printStackTrace();
????????}?finally?{
????????????try?{
????????????????reader.close();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????????connection.disconnect();
????????}
????}






//Post請(qǐng)求
private?static?void?httpURLPOSTCase()?{
????String?methodUrl?=?“http://127.0.0.1:8099/select_by_id?userid=1“;
????HttpURLConnection?connection?=?null;
????OutputStream?dataout?=?null;
????BufferedReader?reader?=?null;
????String?line?=?null;
????try?{
????????URL?url?=?new?URL(methodUrl);
????????connection?=?(HttpURLConnection)?url.openConnection();//?根據(jù)URL生成HttpURLConnection
????????connection

評(píng)論

共有 條評(píng)論