您可以使用以下代码将该字符串转换为JSON并通过POST方法提交到指定的URL:/n/nphp/n<?php/n/$data = '{/'data/':[{/'user_id/':2,/'u/':11111,/'d/':11111111},{/'user_id/':3,/'u/':22222,/'d/':2222222}]}';/n/n// Convert string to JSON/n/$jsonData = json_encode(/$data);/n/n// Prepare POST request/n/$ch = curl_init();/ncurl_setopt(/$ch, CURLOPT_URL, 'https://example.com/your-endpoint');/ncurl_setopt(/$ch, CURLOPT_POST, 1);/ncurl_setopt(/$ch, CURLOPT_POSTFIELDS, /$jsonData);/ncurl_setopt(/$ch, CURLOPT_RETURNTRANSFER, true);/n/n// Send POST request/n/$response = curl_exec(/$ch);/n/n// Check if request was successful/nif (/$response === false) {/n echo /'请求失败/';/n} else {/n echo /$response;/n}/n/n// Close curl handle/ncurl_close(/$ch);/n?>/n/n/n请将https://example.com/your-endpoint替换为您要提交的URL。

PHP 使用 cURL 将 JSON 字符串 POST 到指定 URL - 代码示例

原文地址: https://www.cveoy.top/t/topic/qo0f 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录