外置接口請求

1. 請求接口json

/**
 * 請求接口
 *
 * @param url
 * @param paramsStr
 * @param type      Connection.Method.POST
 * @param heads
 * @return
 */
public JSONObject sendUpload(String url, String paramsStr, Connection.Method type, Map<String, String> heads) {
    //發送上傳訂單請求
    String erpUploadResponse = null;
    try {
        Connection connection = Jsoup.connect(url).ignoreContentType(true)
                .header("Accept", "*/*")
                .header("Content-Type", "application/json; charset=UTF-8")
                .method(type)
                .timeout(2000000);
        if (heads != null) {
            for (Map.Entry<String, String> entry : heads.entrySet()) {
                connection.header(entry.getKey(), entry.getValue());
            }
        }
        if (type == Connection.Method.POST) {
            connection.requestBody(paramsStr);
        }
        erpUploadResponse = connection.execute().body();
    } catch (IOException e) {
        logger.error("## FEITE面單上傳接口出錯!URL={},param={}, type={}", url, paramsStr, type);
    }

    return JSONObject.parseObject(erpUploadResponse);
}

2. 請求方式 app

JSONObject responseJson = sendUpload(erpQueryTraceId, JSON.toJSONString(param), Connection.Method.POST, null);
相關文章
相關標籤/搜索