javaAPI接口文档方法调用

更新时间:2023-07-25 16:10:59 阅读: 评论:0

javaAPI接⼝⽂档⽅法调⽤
1.创建.properties⽂件,将请求的url写⼊该⽂件,这样更改请求路径时不⽤更改代码。
日不落英文版
2.获取配置⽂件中的url,调⽤url.openConnection实现接⼝调⽤
package com.ify.nder;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.HttpURLConnection;
shemales
import java.URL;
import java.URLConnection;
SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import s.logging.Log;
import s.logging.LogFactory;
le.gson.Gson;
import st.monitor.persistence.bo.TaskResult;
import st.notify.NotifySender;
import del.REST_CallResult;
简爱读后感英文import st.task.persistence.bo.TaskDefinition;
public class ExceptionNotifySender implements NotifySender{
private static Log log = Log(ExceptionNotifySender.class);
@Override
public void nd(TaskDefinition task, TaskResult taskResult) {
Properties p = new Properties();
工程建造师报考条件try {
//加载配置⽂件
p.load(ResourceAsStream("/st.properties"));
//获取配置⽂件中的请求路径,并进⾏相应的设置
URL localURL = new Property("ption.url"));
URLConnection connection = localURL.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
httpURLConnection.tDoOutput(true);
httpURLConnection.tRequestProperty("Accept-Chart", "utf-8");
//这⾥是post请求
httpURLConnection.tRequestMethod("POST");
httpURLConnection.tConnectTimeout(30000);
//获取参数
String taskName = Name();
Long taskDefId = Id();
Long taskResultId = Id();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = format.format(new Date());
//传参⽅式,多个参数
String content = "taskName="+ taskName + "&taskDefId=" + taskDefId + "&taskResultId=" + taskResultId + "&time=" + time + "&message=123";  BufferedOutputStream outBuf = new OutputStream());
outBuf.Bytes());
outBuf.flush();
should//获取返回值
byte[] bu = new byte[1024];
储物间英文int readLength = -1;
高中 英语InputStream inputStream = InputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((readLength = ad(bu, 0, bu.length)) != -1) {
out.write(bu, 0, readLength);
}
byte[] comfirm = ByteArray();
//关闭IO流
outBuf.clo();idb
inputStream.clo();
out.clo();
String string = new String(comfirm, "UTF-8");//返回值
REST_CallResult CallResult = new REST_CallResult();
/
/使⽤new Gson().fromJson反序列化成类
REST_CallResult fromJson = new Gson().fromJson(string, Class());  //⽇志打印
log.info("异常发⽣调⽤返回----"+String());
} catch (IOException e) {
siase.printStackTrace();
<("ExceptionNotifySender--->>>nd----调⽤失败");
}
}
public static void main(String[] args){
TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.tId((long) 1);
taskDefinition.tName("task1");
TaskResult taskResult = new TaskResult();
taskResult.tId((long) 1);
ExceptionNotifySender exceptionNotifySender = new ExceptionNotifySender();
exceptionNotifySender.nd(taskDefinition,taskResult);
}
}tome

本文发布于:2023-07-25 16:10:59,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/188443.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:获取   路径   配置
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图