URL 渲染
参数说明
JSON
参数 | 必需 | 说明 |
---|---|---|
url | 是 | string,需要渲染模板的 URL |
headers | 否 | object,请求 URL 自定义的请求头 |
headers
headers 对应 HTTP 请求头,用于快海报服务请求你所提供的 url
所携带的额外请求头。参数支持没有限制,只要是合法的 HTTP Headers 均可支持。
如果不提供 headers
字段,快海报将遵循 海报生成 API 中 device
或 custom_device
信息进行 User-Agent
等字段的默认填充。不提供 headers
字段不代表请求不携带任何 HTTP Headers 信息。
以下表格只举例范围有限,实际使用时包括但不限于表格中的内容:
参数 | 必需 | 说明 |
---|---|---|
Authorization | 否 | string,用于携带用户的认证信息 |
Accept-Language | 否 | string,能够接受的返回内容的语言列表 |
… | … | … |
请求样例
cURL
curl -X "POST" "https://api.kuaihaibao.com/services/screenshot" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"url": "https://kuaihaibao.com/doc/docs/url.html"
}'
JavaScript (axios 版本)
axios({
"method": "POST",
"url": "https://api.kuaihaibao.com/services/screenshot",
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"data": {
"url": "https://kuaihaibao.com/doc/docs/url.html"
}
})
Python
import requests
response = requests.post(
url="https://api.kuaihaibao.com/services/screenshot",
json={
"url": "https://kuaihaibao.com/doc/docs/url.html"
}
)
Java
import java.io.IOException;
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class SendRequest
{
public static void main(String[] args) {
sendRequest();
}
private static void sendRequest() {
Content content = Request.Post("https://api.kuaihaibao.com/services/screenshot")
.addHeader("Content-Type", "application/json; charset=utf-8")
.bodyString("{ \"url\": \"https://kuaihaibao.com/doc/docs/url.html\" }", ContentType.APPLICATION_JSON)
.execute().returnContent();
System.out.println(content);
}
}
PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.kuaihaibao.com/services/screenshot');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json_array = [
'url' => 'https://kuaihaibao.com/doc/docs/url.html'
];
$body = json_encode($json_array);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
if (!$response) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;
curl_close($ch);
C
using System;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Text;
namespace MyNamespace {
public class MyActivity {
private async Task<bool> khbapisample () {
string url = "https://api.kuaihaibao.com/services/screenshot";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (new Uri(url));
request.ContentType = "application/json; charset=utf-8";
request.Method = "POST";
string postData = "{\"url\":\"https://kuaihaibao.com/doc/docs/url.html\"}";
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);
request.ContentLength = byte1.Length;
Stream newStream = request.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
newStream.Close ();
using (WebResponse response = await request.GetResponseAsync ()) {
using (Stream stream = response.GetResponseStream ()) {
return true;
//process the response
}
}
}
}
}