Http
<p>[TOC]</p>
<h2>HttpUtil</h2>
<h3>1. get</h3>
<pre><code class="language-javascript">//简单使用
html = HttpUtil.get(&quot;http://jsdroid.com&quot;)
print(html)
//带参数
params = {&quot;name&quot;:&quot;张三&quot;,&quot;age&quot;:&quot;10&quot;}
html = HttpUtil.get(&quot;http://jsdroid.com&quot;,params)
print(html)
//带请求头
headers = {
&quot;Cookie&quot;:&quot;cookie1=1;cookie2=2&quot;,
&quot;User-Agent&quot;:&quot;Mozilla/5.0&quot;
}
html = HttpUtil.get(&quot;http://jsdroid.com&quot;, headers, params)
print(html)
//全部json形式
req = {
&quot;url&quot;:&quot;http://jsdroid.com&quot;,
&quot;headers&quot;:{
&quot;Cookie&quot;:&quot;cookie1=1;cookie2=2&quot;,
&quot;User-Agent&quot;:&quot;Mozilla/5.0&quot;
},
&quot;params&quot;:{
&quot;name&quot;:&quot;张三&quot;,
&quot;age&quot;:&quot;10&quot;
}
}
html = HttpUtil.get(req)
print(html)
</code></pre>
<h3>2. post</h3>
<pre><code class="language-javascript">//带参数
params = {
&quot;name&quot;:&quot;张三&quot;,
&quot;age&quot;:&quot;10&quot;
}
html = HttpUtil.post(&quot;http://jsdroid.com&quot;, params)
print(html)
//带请求头
headers = {
&quot;Cookie&quot;:&quot;cookie1=1;cookie2=2&quot;,
&quot;User-Agent&quot;:&quot;Mozilla/5.0&quot;
}
html = HttpUtil.post(&quot;http://jsdroid.com&quot;, headers, params)
print(html)
//全部json形式
req = {
&quot;url&quot;:&quot;http://jsdroid.com&quot;,
&quot;headers&quot;:{
&quot;Cookie&quot;:&quot;cookie1=1;cookie2=2&quot;,
&quot;User-Agent&quot;:&quot;Mozilla/5.0&quot;
},
&quot;params&quot;:{
&quot;name&quot;:&quot;张三&quot;,
&quot;age&quot;:&quot;10&quot;
}
}
html = HttpUtil.post(req)
print(html)</code></pre>