-1

I was given a json file and it need to convert into a php curl but I don't have idea how to do it. can some enlighten me or guide me?

here is the json data given

"request": {
        "auth": {
            "type": "basic",
            "basic": [
                {
                    "key": "password",
                    "value": "",
                    "type": "string"
                },
                {
                    "key": "username",
                    "value": "",
                    "type": "string"
                }
            ]
        },
        "method": "PUT",
        "header": [
            {
                "key": "Content-Type",
                "name": "Content-Type",
                "value": "application/x-www-form-urlencoded",
                "type": "text"
            },
            {
                "key": "Authorization",
                "value": "Basic M6NDhhODhjYWUwY2Y0NDE",
                "type": "text",
                "disabled": true
            }
        ],
        "body": {
            "mode": "formdata",
            "formdata": [
                {
                    "key": "invoice",
                    "type": "file",
                    "src": "file.xml"
                },
                {
                    "key": "invoice",
                    "type": "file",
                    "src": [],
                    "disabled": true
                }
            ],
            "options": {
                "raw": {
                    "language": "xml"
                }
            }
        }
    }

and the requirements it to create a PUT request using PHP curl. I hope someone could help :)

I saw a sample here PHP cURL HTTP PUT but I don't know where to put the username and password credentials

pal3
  • 241
  • 1
  • 2
  • 13
  • There's a list of [available curl_opt](https://www.php.net/manual/en/function.curl-setopt.php): `CURLOPT_USERNAME` and `CURLOPT_USERPWD` might help – brombeer Feb 27 '20 at 10:32

1 Answers1

0

You can use header option (-H) for example:

curl -XPUT -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Basic M6NDhhODhjYWUwY2Y0NDE' -d '>>body content here<<' 'example.com'

so php equivalent will be:

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers)
Beniamin
  • 550
  • 1
  • 4
  • 13