package com.bootdo.common.utils;


import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * heep delete方法
 *
 * @author Mr.xiBel
 */
//@Slf4j
public class HttpDeleteThread {
    @SuppressWarnings("unused")
    private static final String TAG = "HttpDeleteThread";


    public static String run(String url, String token) {
        String response;
        HttpClient client = new DefaultHttpClient();
        HttpDelete delete = new HttpDelete(url);
        HttpResponse httpResponse;
        try {
            delete.setHeader("Authorization", "Bearer " + token);
            httpResponse = client.execute(delete);
            int statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_OK) {
                response = EntityUtils.toString(httpResponse.getEntity());
                //log.info("method : HttpDeleteThread, response statusCode: {}, Result: {}", statusCode, response);
                return response;
            } else {
                //log.info("HttpDeleteThread, response statusCode: {} ....", statusCode);
                return statusCode + "";
            }
        } catch (IOException e) {
            e.printStackTrace();
            //log.error("method : HttpDeleteThread, timeOut....");
            return "timeOut";
        }


    }
}
