Sure, here's an example of how you can use `curl` to POST JSON data:
Let's say you have a JSON object that you want to send as a POST request to a server:
```json
{
"name": "John Doe",
"email": "john.doe@example.com"
}
```
You would use `curl` in the following way:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","email":"john.doe@example.com"}' http://your-server-address/your-endpoint
```
Here's what's happening in this command:
- `-X POST`: This tells `curl` to use the POST method for the request.
- `-H "Content-Type: application/json"`: This is setting a request header specifying that the content type of the data we're sending is JSON.
- `-d '{"name":"John Doe","email":"john.doe@example.com"}'`: This is the data we're sending in our POST request. The `-d` stands for "data".
- `http://your-server-address/your-endpoint`: This is the URL that you're sending the POST request to. Replace this with the actual URL for your use case.
Please replace `http://your-server-address/your-endpoint` and the JSON payload with your actual server URL and the JSON data you want to send, respectively.
-----------------------
스크립트로 실행 할거야. 내려쓰기로 정리좀 해줘
-----------------------
#!/bin/bash
# API endpoint URL
URL="http://your-server-address/your-endpoint"
# JSON 데이터
JSON_DATA='{
"name":"John Doe",
"email":"john.doe@example.com"
}'
# curl로 POST 요청
curl -X POST \
-H "Content-Type: application/json" \
-d "$JSON_DATA" \
$URL
'오늘의 CHATGPT' 카테고리의 다른 글
nginx 무정지 로드밸런싱 교체. (0) | 2023.07.20 |
---|---|
[Spring Boot] STOMP 로 웹소켓 연동 시 일반 Controller로 요청 받고 원하는 채팅방에 메시지 보낼 수 있는 방법 (0) | 2023.07.10 |
vi 주석 파란색으로 다른색으로 좀 바꿔줘 (0) | 2023.06.29 |
local profile 에서는 spring session을 쓰고 싶지 않아. (0) | 2023.06.26 |
java for문안의 switch에서 continue; 사용하면 어떻게 되나? (0) | 2023.06.13 |
java.util.zip.ZipEntry.getSize() 의 반환값은 무슨 단위야? (0) | 2023.06.13 |
논리erd와 물리erd가 구분되는 이유는 뭐지? (0) | 2023.06.12 |
java ZipEntry 의 getName 할 때 directory 구분기호가 뭐야? (0) | 2023.06.12 |