拉卡拉商户进件java实现合同下载
时间: 2023-07-11 22:47:29 浏览: 93
拉卡拉商户进件接口文档中提供了合同下载的接口,Java代码实现如下:
```java
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class LKLContractDownload {
public static void main(String[] args) {
String urlStr = "http://xxx.xxx.xxx.xxx:xxxx/lkl/file/download";
String token = "your_token_here";
String contractNo = "your_contract_no_here";
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", token);
conn.setDoOutput(true);
String input = "{\"contractNo\":\"" + contractNo + "\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String output;
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
其中,`urlStr` 是合同下载接口的 URL,`token` 是接口认证所需的 token,`contractNo` 是要下载合同的编号。根据实际情况修改这三个参数即可。
阅读全文