请求的接口文档
Url: https://nesting.lyntime.com/optimized_nesting/nesting
Method: POST
Header:
Content-Type:application/json
AppKey:填入申请的AppKey
Authorization:Bearer token (注意Bearer后有一个空格)
Json Body 示例: 下面就是要传递的参数Body
{
“parts”: [
{
“dxf_path”: “dxf/1-y30.dxf”,
“part_name”: “1-y30.dxf”,
},
{
“part_name”: “2-y3.dxf”,
“dxf_path”: “dxf/2-y3.dxf”
}
],
“advance_direction_max_part_depth”: 450,
“sheet_length”: 2440,
“sheet_width”: 1220
}
代码
//调用接口(PostURl:接口地址,Body:JSON数据,key:钥匙,token:请求所需的token)
public string PostWebReq(string PostUrl, string Body, string Key, string token)
{
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(Body); //将字符串编为一个序列
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //安全包支持的安全协议
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(PostUrl));
webReq.Method = "POST";
webReq.ContentType = "application/json";
webReq.ContentLength = byteArray.Length;
webReq.Headers.Add("AppKey", Key); //在Headers 头部添加AppKey 参数
if (!string.IsNullOrEmpty(token))
{
token = string.Concat("Bearer ", token); //组合字符串
webReq.Headers.Add("Authorization", token); //在Headers 头部添加Authorization 参数
}
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
string ReturnVal = reader.ReadToEnd();
reader.Close();
response.Close();
webReq = null;
return ReturnVal;
}
catch (Exception ex)
{
throw new Exception("接口:"+ex.Message);
}
}