{"id":291747,"date":"2019-07-07T15:00:57","date_gmt":"2019-07-07T15:00:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=291747"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=291747","title":{"rendered":"\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 HttpUrlConnection \u0438\u0437 java.net"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435,<\/p>\n<p>  \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 HTTP \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f URLConnection \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 JRE.<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0438\u0437\u0443\u0447\u0430\u0435\u043c Java \u0432 \u043e\u043d\u043b\u0430\u0439\u043d \u0440\u0435\u0436\u0438\u043c\u0435. \u0412\u0441\u044f \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Slack \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0417\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Slack API. \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u0441\u0430\u043c API (\u044d\u0442\u043e \u0442\u0435\u043c\u0430 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438), \u0441\u043a\u0430\u0436\u0443 \u043a\u043e\u0440\u043e\u0442\u043a\u043e: \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 URI \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 API (\u0442\u043e \u0435\u0441\u0442\u044c, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u2013 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u0435\u043d \u0431\u044b\u043b \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u044e\u0437\u0435\u0440\u043e\u0432) \u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 slack-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u044e\u0437\u0435\u0440\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c GET-\u0437\u0430\u043f\u0440\u043e\u0441 \u0441 URL <a href=\"https:\/\/slack.com\/api\/users.list\">slack.com\/api\/users.list<\/a>, \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435 application\/x-www-form-urlencoded, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a (\u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0436\u0435): <\/p>\n<pre><code class=\"plaintext\">GET \/users.list HTTP\/1.1 Content-Type: application\/x-www-form-urlencoded  token=xoxp-1234567890-098765-4321-a1b2c3d4e5&limit=100 <\/code><\/pre>\n<p>  (\u0433\u0434\u0435 limit=100 \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044e\u0437\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c)<\/p>\n<p>  \u042f \u0437\u043d\u0430\u043b \u043f\u0440\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Apache HttpComponents, \u043d\u043e \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u0418, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0438\u0437 HttpUrlConnection, \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 URLConnection \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 java.net.URL, \u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0438\u043f String \u0433\u0434\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u2013 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 https.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 URL, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <i>openConnection()<\/i> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442 \u043d\u0430\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c HttpsUrlConnection.<\/p>\n<pre><code class=\"java\">String url = \u201chttps:\/\/slack.com\/api\/users.list\u201d; URLConnection connection = new URL(url).openConnection(); <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c MalformedUrlException \u0438 IOException. <\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f connection \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 HttpsUrlConnectionImpl. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f GET-\u0437\u0430\u043f\u0440\u043e\u0441, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c Header \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <i>setRequestProperty()<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 key \u0438 value. \u041d\u0430\u043c \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Content-Type \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <i>application\/x-www-form-urlencoded<\/i>. \u041d\u0443, \u0438 \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c!<\/p>\n<pre><code class=\"java\">connection.setRequestProperty(\u201cContent-Type\u201d, \u201capplication\/x-www-form-urlencoded\u201d); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u043f\u0438\u0441\u0430\u0432 \u0432 \u0442\u0435\u043b\u043e \u043d\u0430\u0448 \u0442\u043e\u043a\u0435\u043d \u0438 \u043b\u0438\u043c\u0438\u0442. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 doOutput \u043e\u0431\u044a\u0435\u043a\u0442\u0430 connection \u0432 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 true, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 <i>setDoOutput()<\/i>;<\/p>\n<pre><code class=\"java\">connection.setDoOutput(true); <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u0438 \u0432\u0435\u0441\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 OutputStream). \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OutputStreamWriter:<\/p>\n<pre><code class=\"java\">OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441: \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u044b\u0437\u0432\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 getOutputStream() \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 POST, \u0442\u0430\u043a \u043a\u0430\u043a GET \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 request body, \u043d\u043e \u0431\u043b\u0430\u0433\u043e \u0447\u0442\u043e slack \u043d\u0438 \u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0432\u0451\u0440\u0434\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e. \u0418 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 GET-\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"plaintext\">GET \/users.list?token=xoxp-1234567890-098765-4321-a1b2c3d4e5&limit=100 HTTP\/1.1 Content-Type: application\/x-www-form-urlencoded <\/code><\/pre>\n<p>  \u041d\u043e \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c. \u0418 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code class=\"plaintext\">POST \/users.list HTTP\/1.1 Content-Type: application\/x-www-form-urlencoded  token=xoxp-1234567890-098765-4321-a1b2c3d4e5&limit=100 <\/code><\/pre>\n<p>  (*\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 headers \u0441\u0442\u0430\u0432\u044f\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c HttpsUrlConnection \u0438 \u0437\u0434\u0435\u0441\u044c \u043e\u043d\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442)<\/p>\n<p>  \u0418 \u0442\u0430\u043a \u0447\u0442\u043e\u0431 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f write();.  <\/p>\n<pre><code class=\"java\">String reqBody = \u201ctoken=xoxp-1234567890-098765-4321-a1b2c3d4e5&limit=100\u201d; writer.write(reqBody); writer.close(); <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u042f \u043b\u0438\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b BufferedReader \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438.<\/p>\n<pre><code class=\"java\">StringBuilder respBody = new StringBuilder(); BufferedReader reader = new BufferedReader(connection.getInputStream()); reader.lines().forEach(l -&gt; respBody.append(l + \u201c\\r\\n\u201d); reader.close(); <\/code><\/pre>\n<p>  (*\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c lines() \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Stream \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435; \\r\\n \u2013 \u0441\u0438\u043c\u0432\u043e\u043b CRLF \u2013 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443)<\/p>\n<p>  \u0418, \u0435\u0441\u043b\u0438 \u043c\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f respBody \u0434\u043e\u043b\u0436\u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f JSON \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  \u0412\u043e\u0442 \u0447\u0442\u043e \u0432\u044b\u0448\u043b\u043e:<\/p>\n<pre><code class=\"java\">public static String getRawResponseFromSlack()                 throws MalformedURLException, IOException { \tString url = &quot;https:\/\/slack.com\/api\/users.list&quot;; \tString reqBody = &quot;token=xoxp-23476289909-566592298292&quot; \t\t+ &quot;-682762141574-f0a9feac56d087769519f610b30bd29f&quot; \t\t+ &quot;&limit=100&quot;; \tURLConnection connection = new URL(url).openConnection(); \tconnection.setRequestProperty(&quot;Content-Type&quot;, \t\t&quot;application\/x-www-form-urlencoded&quot;); \t\t \tconnection.setDoOutput(true);  \tOutputStreamWriter out = new OutputStreamWriter( \t\t\tconnection.getOutputStream()); \tout.write(reqBody); \tout.close();  \tStringBuilder respBody = new StringBuilder(); \tBufferedReader reader = new BufferedReader( \t\t\tnew InputStreamReader(connection.getInputStream())); \treader.lines().forEach(l -&gt; respBody.append(l + &quot;\\r\\n&quot;)); \treader.close();  \treturn respBody.toString(); }\t <\/code><\/pre>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e!<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/459080\/\"> https:\/\/habr.com\/ru\/post\/459080\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435,<\/p>\n<p>  \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 HTTP \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f URLConnection \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 JRE.<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0438\u0437\u0443\u0447\u0430\u0435\u043c Java \u0432 \u043e\u043d\u043b\u0430\u0439\u043d \u0440\u0435\u0436\u0438\u043c\u0435. \u0412\u0441\u044f \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Slack \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0417\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Slack API. \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u0441\u0430\u043c API (\u044d\u0442\u043e \u0442\u0435\u043c\u0430 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438), \u0441\u043a\u0430\u0436\u0443 \u043a\u043e\u0440\u043e\u0442\u043a\u043e: \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 URI \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 API (\u0442\u043e \u0435\u0441\u0442\u044c, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u2013 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u0435\u043d \u0431\u044b\u043b \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u044e\u0437\u0435\u0440\u043e\u0432) \u0438 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 slack-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u044e\u0437\u0435\u0440\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c GET-\u0437\u0430\u043f\u0440\u043e\u0441 \u0441 URL <a href=\"https:\/\/slack.com\/api\/users.list\">slack.com\/api\/users.list<\/a>, \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435 application\/x-www-form-urlencoded, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a (\u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0436\u0435): <\/p>\n<pre><code class=\"plaintext\">GET \/users.list HTTP\/1.1 Content-Type: application\/x-www-form-urlencoded  token=xoxp-1234567890-098765-4321-a1b2c3d4e5&#038;limit=100 <\/code><\/pre>\n<p>  (\u0433\u0434\u0435 limit=100 \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044e\u0437\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c)<\/p>\n<p>  \u042f \u0437\u043d\u0430\u043b \u043f\u0440\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Apache HttpComponents, \u043d\u043e \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u0418, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0438\u0437 HttpUrlConnection, \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-291747","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291747"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291747\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}