<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/post//</link>
<title><![CDATA[Hutool工具类HttpUtil使用Https]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Thu, 18 Feb 2021 04:02:08 +0000</pubDate> 
<guid>https://www.heckjj.com/post//</guid> 
<description>
<![CDATA[ 
	关于Hutool工具类之HttpUtil如何使用可以参考官方文档Hutool之HttpUtil<br/><br/>其实使用Http和Https使用的方式是一样的。<br/><br/>建议大家可以看看HttpUtil的源码，感觉设计的挺不错的。<br/><br/>导入Maven依赖<br/> &lt;dependency&gt;<br/>&nbsp;&nbsp; &lt;groupId&gt;cn.hutool&lt;/groupId&gt;<br/>&nbsp;&nbsp; &lt;artifactId&gt;hutool-all&lt;/artifactId&gt;<br/>&nbsp;&nbsp; &lt;version&gt;4.1.0&lt;/version&gt;<br/>&lt;/dependency&gt;<br/>编写测试类(使用Junit单元测试)<br/><br/>@Test<br/>public void testHttps() throws Exception &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;JSONObject json = new JSONObject();<br/>&nbsp;&nbsp;&nbsp;&nbsp;json.put(&quot;username&quot;, &quot;1332788xxxxxx&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;json.put(&quot;password&quot;, &quot;123456.&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;String result = HttpRequest.post(&quot;https://api.heckjj.com/1/users&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.header(&quot;Content-Type&quot;, &quot;application/json&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.header(&quot;X-heck-Application-Id&quot;,&quot;2f0419a31f9casdfdsf431f6cd297fdd3e28fds4af&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.header(&quot;X-heck-REST-API-Key&quot;,&quot;1e03efdas82178723afdsafsda4be0f305def6708cc6&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.body(json)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.execute().body();<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(result);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&#125;<br/><br/>方法解释(上面采用的是一种叫链式编程的方式):<br/>header对应的是请求头。<br/>body对应的是请求体(包含参数和参数值)。<br/>HttpRequest里面包含Post、GET、Delete、Put等常用的RestFul方式。<br/><br/>打印如下:<br/><br/>&#123;&quot;createdAt&quot;:&quot;2019-04-30 10:42:07&quot;,&quot;objectId&quot;:&quot;6cfdb77081&quot;,&quot;sessionToken&quot;:&quot;269e433440c9e65b8058d016df703ccb&quot;&#125;
]]>
</description>
</item><item>
<link>https://www.heckjj.com/post//#blogcomment</link>
<title><![CDATA[[评论] Hutool工具类HttpUtil使用Https]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>