package com.ng.ngtools.Tools;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
/*
 * API支持HTTPS/HTTP测试*
 *
 * @author JustryDeng
 * @DATE 2018年9月13日上午8:36:29
 */
@RestController
public class testAPI {
    /*
     *HTTP/HTTPS发送get请求
     *
     *@DATE 2018年9月13日上午10:21:07*/
    @GetMapping("/get")
    public String testMethodGet(HttpServletRequest request) {//获取URL协议
        String requestURL = request.getRequestURL().toString();
        String protocol = requestURL.split("://")[0];//获取当前URL连接中的端口
        Integer port = request.getServerPort();
        return "get --->" + protocol + "\t" + port;
    }

   //HTTP/HTTPS发送post请求
        //@DATE 2018年9月13日上午10:21:43

    @PostMapping("/post")
    public String testMethodPost(HttpServletRequest request,@RequestBody String bodystring){
//获取URL协议
        String requestURL =request.getRequestURL().toString();
        String protocol =requestURL.split("://")[0];
//获取当前URL连接中的端口
        Integer port =request.getServerPort();
        return "post --->"+protocol +"\t"+port +"\n"+bodystring;
    }


}


