반응형

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

반응형

+ Recent posts