package test;

import static io.restassured.http.ContentType.JSON;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.json.simple.JSONObject;

import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.StringUtils;

import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
import io.restassured.config.RedirectConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.config.SSLConfig;
import io.restassured.http.ContentType;
import io.restassured.http.Header;
import io.restassured.http.Headers;
import io.restassured.response.Response;
import io.restassured.path.json.JsonPath;

public class RequestDataUtils3 {

	//发送post请求前的准备
	private static RestAssured getRMEnv() {
		RestAssured	ra = new RestAssured();
//		ra.config = RestAssuredConfig.newConfig().redirect(RedirectConfig.redirectConfig().followRedirects(false));
		
			ra.config = RestAssuredConfig.newConfig().sslConfig(
					SSLConfig.sslConfig().allowAllHostnames());
//			ra.baseURI = "http://ut1.zuul.pub.puhuifinance.com";
//				ra.port = 8765;
//			ra.basePath = "/bestbuy-app-server-cloud-server/api";
//			ra.config=ra.config().redirect(RedirectConfig.redirectConfig().followRedirects(false));
//			RestAssured.config = ra.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("x-www-form-urlencoded", ContentType.ANY).defaultContentCharset("utf-8"));
		return ra;
	}
	


	//发送post请求返回整个响应结果
	public static Response getPostResponse() {
		RequestDataUtils3 rdu=new RequestDataUtils3();
		Response re=null;                                                                                                        //{}                
//		String url="http://tiku-admin.t.eoffcn.com/mock/mock/checkMockStructure";
//		String url="http://beta.alitest.eoffcn.com/admin/customer/getList?page=1&size=10&username=YS自动化测试&phone=13910960649&:;\\|-+)(*~`.?^%$#@{[]><,card_no=qty50636&status=1";
//		String url="http://beta.alitest.eoffcn.com/admin/customer/getList?page=1&size=10&username=YS自动化测试&phone=13910960649&':;\\|-+)(*~`{}[]><,.?^%$#@!card_no=qty50636&status=1";
//		
////		Map<String,String> cookie=new HashMap<String,String>();
////		cookie.put("admin_login_ssid", "b93213c8832b7a67dbf2447a49d53ba2%3AKxLB1tpQrrkawVyHmUWA4eZBI59G%2BAj4583hbomXbyT7D2ZfAf%2F8rAgpm0H5WNJJ");
//
//		Map<String,String> heard=new HashMap<String,String>();
//		heard.put("Cookie", "PHPSESSID=lebk4ou6nkh0cujq8sphhua05j");
//		heard.put("Cookie", "admin_login_ssid=13627cbdc89e684dcb0ceefdd96ba538%3ARv2kle8zV6RJxEKtcaYgvcRmpxXdSHufLyJ7Vg8pXkFyAof%2FcrR3GE%2F7TMWsdBd6");
//		
//		Map<String,String> data=new HashMap<String,String>();
//		data.put("user_name", "ys65701");
//		data.put("password", "ys65701");

		//		m.put("password", "ws63417");
//		m.put("code", "7bcdc063c9ed80c9f9fee83f1101aaed");
		
		int state=1;
		while (state < 5) {
			try {
				state++;
				re = rdu.getRMEnv().given()
						.cookie("PHPSESSID", "bulfocqu656jtcp4rsdbinspga")
//						.cookie("admin_login_ssid", "3a7c5474278846348403ec5827ca835c%3APboDnoIZSlAZMuJTyzG5W%2BBYj2%2FzisCD96eoKcHUddRf2Nmg8zKVMWImsj%2BkInw1")
						.when()
						.post("http://tiku-admin.t.eoffcn.com/mock/mock/mockList")
				        .thenReturn();
				
//				String sss=re.asString();
//				String s1ss=re.asString();
				System.out.println(StringUtils.decodeUnicode(re.asString()));
				System.out.println(re.getHeaders().toString());
				System.out.println(re.getStatusCode());
				System.out.println(re.getCookies());
				System.out.println(re.getCookie("Location"));
				JsonPath jp = re.body().jsonPath();
				if (!"200".equals(re.getStatusCode()+"")) {
					Log.logError("请求返回" + re.getStatusCode() + "次。");
				} else {
					return re;
				}
			} catch (Exception e) {
				e.printStackTrace();
				Log.logError("请求超时," + state + "次。");
			}
		}
		return null;
	}
	public static void main(String[] args) throws Exception {

		getPostResponse();
		
	}

}
