从curl检索响应 - php

时间:2018-06-10 12:46:50

标签: php curl

我的卷曲结果有多个http响应,我试图得到" Content-ID"和JSON数据分别从curl中分成一个数组。

我的卷曲反应是这样的:

--batch_-rVp8WeKIGc_AAUK8q4b0lc
Content-Type: application/http
Content-ID: response-3177

HTTP/1.1 200 OK
ETag: "3057267589256000"
Content-Type: application/json; charset=UTF-8
Date: Sun, 10 Jun 2018 12:29:54 GMT
Expires: Sun, 10 Jun 2018 12:29:54 GMT
Cache-Control: private, max-age=0
Content-Length: 1040

{
 "kind": "calendar#event",
 "status": "tentative",
 "created": "2018-06-10T12:29:54.000Z",
 "updated": "2018-06-10T12:29:54.628Z",
 "summary": "",
 "location": "",
 "colorId": "2",
 "start": {
  "dateTime": "2018-06-30T11:00:00+03:00",
 },
 "end": {
  "dateTime": "2018-06-30T11:30:00+03:00",
 },
 "sequence": 1,
 "reminders": {
  "useDefault": true
 }
}

--batch_-rVp8WeKIGc_AAUK8q4b0lc
Content-Type: application/http
Content-ID: response-3178

HTTP/1.1 200 OK
ETag: "3057267589256000"
Content-Type: application/json; charset=UTF-8
Date: Sun, 10 Jun 2018 12:29:54 GMT
Expires: Sun, 10 Jun 2018 12:29:54 GMT
Cache-Control: private, max-age=0
Content-Length: 1040

{
 "kind": "calendar#event",
 "status": "tentative",
 "created": "2018-06-10T12:29:54.000Z",
 "updated": "2018-06-10T12:29:54.628Z",
 "summary": "",
 "location": "",
 "colorId": "2",
 "creator": {
 "start": {
  "dateTime": "2018-06-30T11:30:00+03:00",
 },
 "end": {
  "dateTime": "2018-06-30T12:00:00+03:00",
 },
 "sequence": 1,
 "reminders": {
  "useDefault": true
 }
}

--batch_-rVp8WeKIGc_AAUK8q4b0lc--

对象内包含Content-ID的每个响应的预期结果:

stdClass Object
(
    [contentId] => response-3178
    [kind] => calendar#event
    [status] => tentative
    [created] => 2018-06-10T12:29:54.000Z
    [updated] => 2018-06-10T12:29:54.628Z
    [summary] => 
    [location] => 
    [colorId] => 2
    [start] => stdClass Object
        (
            [dateTime] => 2018-06-30T11:00:00+03:00
        )

    [end] => stdClass Object
        (
            [dateTime] => 2018-06-30T11:30:00+03:00
        )

    [sequence] => 1
    [reminders] => stdClass Object
        (
            [useDefault] => 1
        )

)

我认为实现这一点有点复杂,想听听你的想法。 如果有人有一个简单的解决方案,请发帖。

0 个答案:

没有答案