Apache HttpClient-Http Postリクエスト
POST要求は、サーバーにデータを送信するために使用されます。たとえば、HTMLフォームを使用した顧客情報、ファイルのアップロードなど。
HttpClient APIは、POST要求を表す HttpPost という名前のクラスを提供します。
HttpClientライブラリを使用してHTTP POSTリクエストを送信するには、以下の手順に従います。
ステップ1-HttpClientオブジェクトを作成する
このメソッドを使用して、HttpClientオブジェクトを作成します。
ステップ2-HttpPostオブジェクトを作成する
ステップ3-Getリクエストを実行する
CloseableHttpClientオブジェクトの* execute()*メソッドは、HttpUriRequest(インターフェイス)オブジェクト(つまり、 HttpGet、HttpPost、HttpPut、HttpHeadなど)と応答オブジェクトを返します。
例
以下は、HttpClientライブラリを使用したHTTP POST要求の実行を示す例です。
出力
上記のプログラムは、次の出力を生成します。
Request Type: POST
<!DOCTYPE html>
<!--[if IE 8]><html class = "ie ie8"> <![endif]-->
<!--[if IE 9]><html class = "ie ie9"> <![endif]-->
<!--[if gt IE 9]><!-->
<html lang = "en-US"> <!--<![endif]-->
<head>
<!-- Basic -->
<meta charset = "utf-8">
<title>Parallax Scrolling, Java Cryptography, YAML, Python Data Science, Java
i18n, GitLab, TestRail, VersionOne, DBUtils, Common CLI, Seaborn, Ansible,
LOLCODE, Current Affairs 2018, Apache Commons Collections</title>
<meta name = "Description" content = "Parallax Scrolling, Java Cryptography, YAML,
Python Data Science, Java i18n, GitLab, TestRail, VersionOne, DBUtils, Common
CLI, Seaborn, Ansible, LOLCODE, Current Affairs 2018, Intellij Idea, Apache
Commons Collections, Java 9, GSON, TestLink, Inter Process Communication (IPC),
Logo, PySpark, Google Tag Manager, Free IFSC Code, SAP Workflow"/>
<meta name = "Keywords" content="Python Data Science, Java i18n, GitLab,
TestRail, VersionOne, DBUtils, Common CLI, Seaborn, Ansible, LOLCODE, Gson,
TestLink, Inter Process Communication (IPC), Logo"/>
<meta http-equiv = "X-UA-Compatible" content = "IE = edge">
<meta name = "viewport" conten t= "width = device-width,initial-scale = 1.0,userscalable = yes">
<link href = "https://cdn.muicss.com/mui-0.9.39/extra/mui-rem.min.css"
rel = "stylesheet" type = "text/css"/>
<link rel = "stylesheet" href = "/questions/css/home.css?v = 3"/>
<script src = "/questions/js/jquery.min.js"></script>
<script src = "/questions/js/fontawesome.js"></script>
<script src = "https://cdn.muicss.com/mui-0.9.39/js/mui.min.js"></script>
</head>
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
</script>
</body>
</html>