HTML 渲染

HTML 渲染

参数说明

JSON

参数必需说明
htmlstring,需要渲染模板的 HTML

请求样例

cURL

curl -X "POST" "https://api.kuaihaibao.com/services/screenshot" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "html": "<p>kuaihaibao.com</p>"
}'

JavaScript (axios 版本)

axios({
  "method": "POST",
  "url": "https://api.kuaihaibao.com/services/screenshot",
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  },
  "data": {
    "html": "<p>kuaihaibao.com</p>"
  }
})

Python

import requests
response = requests.post(
  url="https://api.kuaihaibao.com/services/screenshot",
  json={
    "html": "<p>kuaihaibao.com</p>"
  }
)

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("{ \"html\": \"<p>kuaihaibao.com</p>\" }", 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 = [
  'html' => '<p>kuaihaibao.com</p>'
]; 
$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 = "{\"html\":\"<p>kuaihaibao.com</p>\"}";
			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
				}
			}
		}
	}
}