记一次postman转curl过程(解决三个问题)

一、postman如何一键转curl命令

点开对应的请求,点开code,选择curl。复制命令即可

二、curl命令https请求跳过

请求的内容如何是 https的会报错

curl: (60) Peer's Certificate has expired.

只需要在请求的命令上加一个 -k 即可,如下图所示

curl -k --location --request POST 'https://xxxxxx/xxxxx/encrypt' --header 'Authorization: Basic xxxxxxxx=' --header 'Content-Type: application/json;charset=utf-8' --header 'Cookie: KMS_SESSIONID=exxxxxxxxxxxxxxxODg4ODE4fQ.jFg_ErZY5N55PkbkI55h6leAtjBPirN41i1h7va2K3k'

即可跳过https请求

三、执行curl命令argument list too long

利用管道技术,让curl从管道里面读取参数

  1. 将请求体json保存到文本文件中,这里比如为search.txt
  2. 编写curl命令,通过管道读取数据,-d @-
cat search.txt | curl -k --location --request POST 'https://xxxxx:port/xx/xx/xx/xxx' --header 'Authorization: xxxxxxx' --header 'Content-Type: application/json;charset=utf-8' --header 'Cookie: KMS_SESSIONID=xxxxxxxxxxxxxDb2RlIjoieWliYW9iaXNpIiwiZXhwIjoxNjU1ODg4ODE4fQ.jFg_ErZY5N55PkbkI55h6leAtjBPirN41i1h7va2K3k' -d @-

将请求内容放在名为 search.txt下。参数内容使用 -d @- 传输即可。


博主新推出的gitee免费开源项目(商城+APP+小程序+H5),有兴趣的小伙伴可以了解一下。

生鲜商城kxmall-小程序 + App + 公众号H5: kxmall-生鲜商城+APP+小程序+H5。同时支持微信小程序、H5、安卓App、苹果App。支持集群部署,单机部署。可用于B2C商城,O2O外卖,社区超市,生鲜【带配套骑手端配送系统】。kxmall使用uniapp编码。使用Java开发,SpringBoot 2.1.x框架,MyBatis-plus持久层框架、Redis作为缓存、MySql作为数据库。前端vuejs作为开发语言。https://gitee.com/zhengkaixing/kxmall

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个简单的Spring Boot交易示例,包括创建订单,更新订单和取消订单: 首先定义订单实体类Order: ```java @Entity @Table(name = "orders") public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String status; @Column(nullable = false) private Double amount; // getter and setter methods } ``` 定义一个订单仓库接口: ```java public interface OrderRepository extends JpaRepository<Order, Long> { } ``` 创建订单的控制器: ```java @RestController @RequestMapping("/orders") public class OrderController { @Autowired private OrderRepository orderRepository; @PostMapping public Order createOrder(@RequestBody Order order) { order.setStatus("created"); return orderRepository.save(order); } @PutMapping("/{id}") public Order updateOrder(@PathVariable Long id, @RequestBody Order order) { Order existingOrder = orderRepository.findById(id).orElseThrow(() -> new RuntimeException("Order not found")); existingOrder.setStatus(order.getStatus()); existingOrder.setAmount(order.getAmount()); return orderRepository.save(existingOrder); } @DeleteMapping("/{id}") public void cancelOrder(@PathVariable Long id) { Order existingOrder = orderRepository.findById(id).orElseThrow(() -> new RuntimeException("Order not found")); existingOrder.setStatus("cancelled"); orderRepository.save(existingOrder); } } ``` 这个控制器定义了三个HTTP端点,用于创建、更新和取消订单。在创建订单时,订单的状态设置为“created”,在取消订单时,订单的状态设置为“cancelled”。 在启动应用程序之前,需要在application.properties文件中配置数据库连接和Hibernate JPA: ``` spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=root spring.datasource.password=mypassword spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true ``` 启动应用程序后,可以使用curl命令或Postman发送HTTP请求来测试这些端点。例如,要创建一个新订单,可以发送以下POST请求: ``` POST http://localhost:8080/orders { "status": "created", "amount": 100.0 } ``` 响应将返回包含新订单的JSON对象: ``` { "id": 1, "status": "created", "amount": 100.0 } ``` 要更新订单,可以发送以下PUT请求: ``` PUT http://localhost:8080/orders/1 { "status": "paid", "amount": 150.0 } ``` 响应将返回更新后的订单: ``` { "id": 1, "status": "paid", "amount": 150.0 } ``` 要取消订单,可以发送以下DELETE请求: ``` DELETE http://localhost:8080/orders/1 ``` 响应将不包含任何内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

you来有去

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值