Could not resolve host: content.dropboxapi.com when to upload file at shutdown

Solution 1:

method 1: /etc/systemd/system/upload.service
1.1 /etc/systemd/system/upload.service

sudo vim  /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target  reboot.target
Requires=network-online.target
After=network.target    

[Service]
ExecStop=/bin/true
ExecStart=/bin/bash  /home/upload.sh 
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

1.2 vim /home/upload.sh

cd  /home
curl -X POST https://content.dropboxapi.com/2/files/upload \
            --header "Authorization: Bearer xxxx" \
            --header "Dropbox-API-Arg:  {\"path\":\"/test.txt\",\"mode\":{\".tag\":\"overwrite\"}}" \
            --header "Content-Type: application/octet-stream" \
            --data-binary @"test.txt"

1.3 sudo systemctl enable upload.service

method 2: /lib/systemd/system-shutdown/upload.service
2.1 /lib/systemd/system-shutdown/upload.service

sudo vim  /lib/systemd/system-shutdown/upload.service
[Unit]
Description=upload files into dropbox
Before=shutdown.target  reboot.target
Requires=network-online.target
After=network.target    

[Service]
ExecStop=/bin/true
ExecStart=/bin/bash  /home/upload.sh 
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

2.2 vim /home/upload.sh

cd  /home
curl -X POST https://content.dropboxapi.com/2/files/upload \
            --header "Authorization: Bearer xxxx" \
            --header "Dropbox-API-Arg:  {\"path\":\"/test.txt\",\"mode\":{\".tag\":\"overwrite\"}}" \
            --header "Content-Type: application/octet-stream" \
            --data-binary @"test.txt"

2.3 sudo systemctl enable /lib/systemd/system-shutdown/upload.service