HttpService.java 2.06 KB
package com.bsth.serviec_jk.xl_basic;

import com.alibaba.fastjson.JSONObject;
import com.bsth.utils.HttpUtils;
import com.bsth.utils.postUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;


public class HttpService {
    private final static Logger log = LoggerFactory.getLogger(HttpUtils.class);
    
    public static int httpRequestResult(JSONObject json, String token, String url, int count){



        String result= null;
        try {
            result = postUtil.send(url, json, "UTF-8", token);
            System.out.println(result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("返回结果------------------"+result);
        if(result !=null){
            if(result.indexOf("state")!=-1){
                log.info("第"+count+"次调用插入成功!");
                return 1;
            }else {
                log.info("第"+count+"次调用插入失败!");
                return -1;
            }
        }
        log.info("第"+count+"次调用插入未返回数据!");
        return -1;
    }
    
    public static int httpRequestResulty(String json, String token, String url, int count){
        String result= null;
        try {
            result = postUtil.sendy(url, json, "UTF-8", token);
            System.out.println(result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("返回结果------------------"+result);
        if(result !=null){
            if(result.indexOf("state")!=-1){
                log.info("第"+count+"次调用插入成功!");
                return 1;
            }else {
                log.info("第"+count+"次调用插入失败!");
                return -1;
            }
        }
        log.info("第"+count+"次调用插入未返回数据!");
        return -1;
    }
}