diff --git a/src/main/java/com/ly/doc/utils/CurlUtil.java b/src/main/java/com/ly/doc/utils/CurlUtil.java index 467441d0..d202c629 100644 --- a/src/main/java/com/ly/doc/utils/CurlUtil.java +++ b/src/main/java/com/ly/doc/utils/CurlUtil.java @@ -54,16 +54,16 @@ public static String toCurl(CurlRequest request) { if (StringUtil.isNotEmpty(request.getContentType()) && !MediaType.APPLICATION_FORM_URLENCODED_VALUE.equals(request.getContentType())) { sb.append(" -H"); - sb.append(" 'Content-Type: ").append(request.getContentType()).append("'"); + sb.append(" \"Content-Type: ").append(request.getContentType()).append("\""); } if (CollectionUtil.isNotEmpty(request.getReqHeaders())) { for (ApiReqParam reqHeader : request.getReqHeaders()) { sb.append(" -H"); if (StringUtil.isEmpty(reqHeader.getValue())) { - sb.append(" '").append(reqHeader.getName()).append("'"); + sb.append(" \"").append(reqHeader.getName()).append("\""); } else { - sb.append(" '").append(reqHeader.getName()).append(':') - .append(reqHeader.getValue()).append("'"); + sb.append(" \"").append(reqHeader.getName()).append(':') + .append(reqHeader.getValue()).append("\""); } } } diff --git a/src/test/java/com/ly/doc/util/CurlUtilTest.java b/src/test/java/com/ly/doc/util/CurlUtilTest.java new file mode 100644 index 00000000..e2f7aec6 --- /dev/null +++ b/src/test/java/com/ly/doc/util/CurlUtilTest.java @@ -0,0 +1,29 @@ +package com.ly.doc.util; + +import com.ly.doc.constants.ApiReqParamInTypeEnum; +import com.ly.doc.model.ApiReqParam; +import com.ly.doc.model.request.CurlRequest; +import com.ly.doc.utils.CurlUtil; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +public class CurlUtilTest { + /** + * test header name + */ + @Test + public void testHeaderName() { + ApiReqParam apiReqParam = ApiReqParam.builder() + .setName("Authorization") + .setValue("lbEfFvLigPuN2pDMxWaTviVuGwhg74T11geUiNcaYwZ4ZAZB780vkQo8OBMVpZmT") + .setParamIn(ApiReqParamInTypeEnum.HEADER.getValue()); + CurlRequest builder = CurlRequest.builder(); + builder.setUrl("http://127.0.0.1:8080/region/list") + .setType("POST") + .setContentType("application/json") + .setReqHeaders(Arrays.asList(apiReqParam)); + String curl = CurlUtil.toCurl(builder); + System.out.println(curl); + } +}