... | ... | @@ -72,4 +72,27 @@ req.setContentType(Http.ContentTypeJson) |
|
|
req.fetch()
|
|
|
```
|
|
|
|
|
|
##### 获取一张图片数据,例如一张验证码
|
|
|
|
|
|
```javascript
|
|
|
var req = new Http("http://zgcx.nhfpc.gov.cn/pn.aspx");
|
|
|
//设置为post请求
|
|
|
req.setMethod(Http.POST);
|
|
|
//设置user-agent
|
|
|
req.addHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36")
|
|
|
//设置referer
|
|
|
req.addHeader("Referer","http://jianguan.12301.cn/");
|
|
|
req.addHeader("Cookie","ASP.NET_SessionId=tdp2ajtfa0pmiqywmli0pmol");
|
|
|
req.setOnSuccess(function(d){
|
|
|
var image = new Image();
|
|
|
image.src = d;
|
|
|
image.style.position = "absolute"
|
|
|
image.style.left = 0;
|
|
|
image.style.top = 0;
|
|
|
document.body.appendChild(image);
|
|
|
});
|
|
|
//设置请求方式为json
|
|
|
req.setContentType(Http.ContentTypeJson)
|
|
|
req.fetch()
|
|
|
```
|
|
|
|