![](/img/trans.png)
[英]PHP Rest Server not receiving $_POST when URLRequestHeader is set in flash
[英]POST to REST server by php
我想使用php在我擁有的服務器上發布帖子。
我在想卷曲,但我找到的所有示例都是urlfy數據,我必須發送一個json文件,但不在URL中發送。
我已經在數組中添加了json:'key'=>'value'...
我必須添加標題,我想可以這樣:
curl_setopt($ch,CURLOPT_HTTPHEADER,array('HeaderName: HeaderValue','HeaderName2: HeaderValue2'));
但是我不知道如何添加我的數組並發布它。
任何想法?
我需要添加一個像這樣的json:
[{"a":"q",
"b":"w",
"c":[{
"e":"w",
"r":"t"
}]
}]
在這里,您可以使用CURL發布數據,並且如前所述,您已經擁有一個json,您可以這樣做
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'your api end point');
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); // $postfields is the json that you have
$request_headers = array();
$request_headers[] = 'HeaderName: HeaderValue','HeaderName2: HeaderValue2';
$request_headers[] = 'Content-Type: application/json','Content-Length: ' . strlen($postfields) ;
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$response = curl_exec($ch);
curl_close ($ch);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.