• 首页
  • 产品
  • 体验一下
  • 价格
  • 客户案例
  • 开发者文档
  • 关于我们
  • 获取测试包及报价

  • 在线咨询

  • 联系我们

永中DCS调用说明
本文列举了永中DCS文档在线预览的各个语言的简单调用说明,您需要详细文档可以咨询在线客服。

1.上传接口

//上传文件

public static String postParams(String url, String filepath, String type){

CloseableHttpClient httpclient =HttpClients.createDefault();

CloseableHttpResponse response = null;

String result = null;

try {接口文档及调用示例

HttpPost httpPost = new HttpPost(url);

MultipartEntityBuilder mEntityBuilder =

MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER _COMPATIBLE);

mEntityBuilder.setCharset(Charset.forName("UTF-8"));

FileBody file = new FileBody(new File(filepath));

mEntityBuilder.addPart("file", file);

StringBody comment = new StringBody(type,

ContentType.APPLICATION_JSON);

mEntityBuilder.addPart("convertType", comment);

HttpEntity reqEntity =mEntityBuilder.build();

httpPost.setEntity(reqEntity);

response = httpclient.execute(httpPost);

int statusCode =

response.getStatusLine().getStatusCode();

if (statusCode == HttpStatus.SC_OK) {

HttpEntity resEntity = response.getEntity();

byte [] josn = EntityUtils.toByteArray(resEntity);

result = new String(josn,"UTF-8");

EntityUtils.consume(resEntity);

}

catch (Exception e) {

e.printStackTrace();

} finally {

HttpClientUtils.closeQuietly(httpclient);

HttpClientUtils.closeQuietly(response);

}

return result;

}

2.下载接口

public static String sendPost(String serverurl,Map< String,String>param){

List< NameValuePair> list = new ArrayList<

NameValuePair>();

String fullurl ="";

//请求参数

for(String key : param.keySet()) {

list.add(new BasicNameValuePair(key, param.get(key)));

}

try{

fullurl = EntityUtils.toString(new

UrlEncodedFormEntity(list, Consts.UTF_8));

}catch(Exception e){

result ="下载失败";

e.printStackTrace();

}

HttpPost httpget = new HttpPost(serverurl+"?"+fullurl);

CloseableHttpClient httpclient =

HttpClients.createDefault();

try (CloseableHttpResponse response =

httpclient.execute(httpget)){

if (response.getStatusLine().getStatusCode() == 200) {

HttpEntity resEntity = response.getEntity();

byte [] josn = EntityUtils.toByteArray(resEntity);

result = new String(josn,"UTF-8");

EntityUtils.consume(resEntity);

}else{

result="下载失败";

}

} catch (Exception e) {

result="下载失败";

e.printStackTrace();

} finally{

httpget.releaseConnection();

}

return result;

}

1.上传接口

public static string HttpUploadFile(string url, string path, int Content_Type){

FileStream fs = new FileStream(path, FileMode.Open,

FileAccess.Read);

byte[] bArr = new byte[fs.Length];

fs.Read(bArr, 0, bArr.Length);

fs.Close();

int pos = path.LastIndexOf("\\");

string fileName = path.Substring(pos + 1);

string boundary =

"Boundary-b1ed-4060-99ls-fca7ff59c113"; //Could be any string

string Enter = "\r\n";

//part 1 注意 filename 不支持中文

string part1 = "--" + boundary + Enter

+ "Content-Type: text/plain" + Enter

+ "Content-Disposition: form-data; filename=\"" +

"fileName.doc" + "\"; name=\"file\"" + Enter + Enter;

//part 2

string part2 = Enter

+ "--" + boundary + Enter

//+ "Content-Type: text/plain" + Enter

+ "Content-Disposition: form-data;

name=\"convertType\"" + Enter + Enter

+ Content_Type + Enter

//以下是我们的通用参数

//start

+ "--" + boundary + Enter

+ "Content-Disposition: form-data;

name=\"edcoding\"" + Enter + Enter

+ "utf-8" + Enter

//end

//start

/*

+ "--" + boundary + Enter

+ "Content-Disposition: form-data;

name=\"htmlTitle\"" + Enter + Enter

//end

//start

+ "--" + boundary + Enter

+ "Content-Disposition: form-data;

+ "Content-Disposition: form-data;

+ "0" + Enter

//end

//start

+ "--" + boundary + Enter

+ "Content-Disposition: form-data;

name=\"showFooter\"" + Enter + Enter

+ "0" + Enter */

//end

+ "--" + boundary + "--";

HttpWebRequest request =

(HttpWebRequest)WebRequest.Create(url);

request.Method = "POST";

request.ContentType =

"multipart/form-data;boundary=" + boundary;接口文档及调用示例

Stream myRequestStream = request.GetRequestStream();

myRequestStream.Write(Encoding.UTF8.GetBytes(part1.ToString()), 0,

part1.Length);

myRequestStream.Write(bArr, 0, bArr.Length);

myRequestStream.Write(Encoding.UTF8.GetBytes(part2.ToString()), 0,

part2.Length);

myRequestStream.Close();

HttpWebResponse response =

(HttpWebResponse)request.GetResponse();

Stream myResponseStream =

response.GetResponseStream();

StreamReader myStreamReader = new

StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

string retString = myStreamReader.ReadToEnd();

//log(retString);

myStreamReader.Close();

myResponseStream.Close();

return retString;

}

static void Main() {

string url = "http://localhost:8080/dcs.web/upload";

string data = "C:/1.txt";

string result = HttpUploadFile(url, data, 1);

Console.WriteLine(result);

}

}

2.下载接口

public string HttpPost(string Url, string postDataStr)

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);

request.CookieContainer = cookie;

Stream myRequestStream = request.GetRequestStream();

StreamWriter myStreamWriter = new StreamWriter(myRequestStream,

Encoding.GetEncoding("gb2312"));

myStreamWriter.Write(postDataStr);

myStreamWriter.Close();

HttpWebResponse

response

=接口文档及调用示例

(HttpWebResponse)request.GetResponse();

response.Cookies = cookie.GetCookies(response.ResponseUri);

Stream myResponseStream = response.GetResponseStream();

StreamReader myStreamReader = new StreamReader(myResponseStream,

Encoding.GetEncoding("utf-8"));

string retString = myStreamReader.ReadToEnd();

myStreamReader.Close();

myResponseStream.Close();

return retString;

}

1.上传文件

function send_file($url, $post = '', $file = '') {

$eol = "\r\n";

$mime_boundary = md5 ( time () );

$data = '';

$confirmation = '';

date_default_timezone_set ( "Asia/Beijing" );

$time = date ( "Y-m-d H:i:s " );

$post ["filename"] = $file [filename];

foreach ( $post as $key => $value ) {

$data .= '--' . $mime_boundary . $eol;

$data .= 'Content-Disposition: form-data; ';

$data .= "name=" . $key . $eol . $eol;

$data .= $value . $eol;

}

$data .= '--' . $mime_boundary . $eol;

$data .= 'Content-Disposition: form-data; name=' . $file [name]. '; filename=' . $file [fi

lename] . $eol;

$data .= 'Content-Type: text/plain' . $eol;

$data .= 'Content-Transfer-Encoding: binary' . $eol . $eol;

$data .= $file [filedata] . $eol;

$data .= "--" . $mime_boundary . "--" . $eol . $eol;

$params = array ('http' => array ('method' => 'POST', 'header'=> 'Content-Type: multipart/

form-data;boundary=' . $mime_boundary . $eol, 'content' => $data) );

$ctx = stream_context_create ( $params );

$response = file_get_contents ( $url, FILE_TEXT, $ctx );

return $response;

}

2.下载接口

$url="http://dcs.yozosoft.com/onlinefile";

$uri="http://dcs.yozosoft.com/example/doc/doctest.docx";

$response=onlinefile($url, $uri);

echo $response;

function onlinefile($url, $uri) {

$data=array('downloadUrl'=> 'http://dcs.yozosoft.com/example/doc/doctest.docx','convertType'=>'1');

$data =

http_build_query($data);

$params= array('http' => array(

'method' => 'POST',

'content' => $data

)

);

print_r($params);

$ctx = stream_context_create($params);

$fp = file_get_contents($url, false, $ctx);

if (!$fp) {

return false;

}

return $fp;

}

1.下载接口

#include "stdafx.h"

#include "DCSTest.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

// 唯一的应用程序对象

CWinApp theApp;

#include iostream

#include string

#include Winsock2.h

using namespace std;

//函数声明

int httpPost(char* hostname, char* api, char* parameters);

//方法调用

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

int nRetCode = 0;

// initialize MFC and print and error on failure

if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),0))

{

// TODO: change error code to suit your needs

_tprintf(_T("Fatal Error: MFC initialization failed\n"));

return 1;

}

httpPost("dcs.yozosoft.com",

"http://dcs.yozosoft.com:80/onlinefile",

"downloadUrl=http://img.iyo

"cloud.com:8000/doctest.docx&convertType=1");

system("pause");

return nRetCode;

}

/*

*post 请求

*参数:hostname 域名

* api 接口

* parameters 参数,请求参数应该是name1=value1&name2=value2 的形式。

*返回:正确0,否则,错误代码

*/

int httpPost(char* hostname, char* api, char* parameters)

{

WSADATA WsaData;

WSAStartup(0x0101, &WsaData);

//初始化socket

struct hostent* host_addr = gethostbyname(hostname);

if (host_addr == NULL)

{

cout<<"Unable to locate host";

return -103;

}

sockaddr_in sin;

sin.sin_family = AF_INET;

sin.sin_port = htons((unsigned short)80);

sin.sin_addr.s_addr = *((int*)*host_addr->h_addr_list);

int sock = socket(AF_INET, SOCK_STREAM, 0);

if (sock == -1)

{

return -100;

}

//建立连接

if (connect(sock, (const struct sockaddr *)&sin,sizeof(sockaddr_in) ) == -1)

{

cout<<"connect failed";

return -101;

}

//初始化发送信息

char send_str[2048] = 0;

//头信息

strcat(send_str, "POST ");

strcat(send_str, api);

strcat(send_str, " HTTP/1.1\r\n");

strcat(send_str, "Host: ");

strcat(send_str, hostname);

strcat(send_str, "\r\n");

strcat(send_str, "Connection: keep-alive\r\n");

char content_header[100];

sprintf(content_header,"Content-Length: %d\r\n", strlen(parameters));

strcat(send_str, content_header);

strcat(send_str, "Cache-Control: max-age=0\r\n");

strcat(send_str, "Origin: http://dcs.yozosoft.com\r\n");

strcat(send_str, "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like G

ecko) Chrome/15.0.849.0 Safari/535.1\r\n");

strcat(send_str, "Content-Type: application/x-www-form-urlencoded\r\n");

strcat(send_str, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r

\n");

strcat(send_str, "Referer: http://dcs.yozosoft.com/\r\n");

strcat(send_str, "Accept-Encoding: gzip,deflate,sdch\r\n");

strcat(send_str, "Accept-Language: zh-CN,zh;q=0.8\r\n");

//内容信息

strcat(send_str, "\r\n");

strcat(send_str, parameters);

if (send(sock, send_str, strlen(send_str),0) == -1)

{

cout<<"send failed";

return -101;

}

//获取返回信息

char recv_str[4096] = 0;

if (recv(sock, recv_str, sizeof(recv_str), 0) == -1)

{

cout<<"recv failed";

return -101;

}

cout<<"recv_str";

WSACleanup( );

return 0;

}

import requests from builtins

import print

def upload():

url = 'http://localhost:8080/dcs.web/upload'

files = {"file": open("D:/1.docx", "rb")}

data = {"convertType":"3"}

response = requests.post(url, files=files, data=data)json =

response.json()

return json;

#print(upload())

print(url())

Web 调用需要配置 jquery 组件,用到 ajax,需要配置 ajaxfileupload.js。

web 要视具体情况来编写代码,下面代码为核心调用部分。

1.上传接口

$('#upfilebtn2').fileupload({

url : 'upload',

dataType : 'json',

formData : {

convertType : "0"

},

//如果需要额外添加参数可以在这里添加

done : function(e, data){

$.isLoading("hide");

}

});

2.下载接口

$.ajax({

url : "onlinefile",

data :{

"downloadUrl" : obj_value,

"convertType" : "0"

},

dataType : "json",

type : "post",

success : function(data){

$.isLoading("hide");

},

error : function(data){

$.isLoading("hide");

console.error(data)

}

})

关于永中DCS文档转换中实例数的设置:我们一般推荐客户按照服务器的硬件条件来设置。例如服务器可用为 4 核配 8G 内存,并发可设置 4-8 个,我们推荐1核1G内存设置1个并发实例 。

tomcat的性能优化:根据设置的实例数和服务器剩余内存数来设置 jvm 的内存设置。

Ⅰ windows 下:

在windows下的tomcat/bin下的catalina.bat中首行加入set JAVA_OPTS=-Xms***m -Xmx***m

Ⅱ Linux 下:

在 linux下的tomcat/bin下的catalina.sh中首行加入 JAVA_OPTS="$JAVA_OPT -Xms***m -Xmx***m"

其中 Xms 表示启动所需最小内存,Xmx 表示可用最大内存,***根据实际情况设置