这里 ;
$json = json_encode($_POST, JSON_UNESCAPED_UNICODE);
if (file_put_contents("data.json", $json));
$request= \Httpful\Request::post($url)
->addHeaders(array(
'Authorization' => "Bearer ".$token,
'Accept' => "application/json"
))
->sendsJson()
->attach(["file"=>"data.json"])
->send();
var_dump($request->body);
如上例所示,我发送一个 json 文件。
有没有办法通过不在目录中创建真实文件而仅使用 $json 变量发送此文件?我希望我很清楚。
这是api服务提供的请求方法;
Method -> POST
Header Variables -> [{"key":"Authorization","value":"Bearer Token"},{"key":"Accept","value":"application/json"}]
Form Parameter -> ProductFile: JSON File
这是 api 服务提供的示例请求;
POST /product/api/products/import HTTP/1.1
Host: ********************.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWASDsa7haY9wX2RldiIsImF1dGgiOiJST0xFX0lOVEVHUkFUT1IsUk9MRV9MT0NBTCIsImV4cCI6MTU2MjY3MzY1NCwidXNlcklkIjoiNWQyMmY3ODA1NmE5M2EwMDBmMWJjYTQ4In0.YJnDZY0tDIwW3GBEFLKvKKuYjTFVNEEsC-JkMBOYS3rJNVc0jlB-1ajKZgH0t-6dtnTwKrfVbW5yOoZxMdDiNg
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="generated(4).json"
Content-Type:
------WebKitFormBoundary7MA4YWxkTrZu0gW--