如何在变量中获取curl的返回值

时间:2015-04-27 10:14:10

标签: php

我有两页。 get.php是

import asyncio
import unittest
from unittest.mock import Mock


class ImGoingToBeMocked:
    @asyncio.coroutine
    def yeah_im_not_going_to_run(self):
        yield from asyncio.sleep(1)
        return "sup"


class ImBeingTested:
    def __init__(self, hidude):
        self.hidude = hidude

    @asyncio.coroutine
    def i_call_other_coroutines(self):
        return (yield from self.hidude.yeah_im_not_going_to_run())


class TestImBeingTested(unittest.TestCase):

    def test_i_call_other_coroutines(self):
        mocked = Mock(ImGoingToBeMocked)
        ibt = ImBeingTested(mocked)

        @asyncio.coroutine
        def mock_coro():
            return "sup"
        mocked.yeah_im_not_going_to_run = mock_coro

        ret = asyncio.get_event_loop().run_until_complete(
            ibt.i_call_other_coroutines())
        self.assertEqual("sup", ret)


if __name__ == '__main__':
    unittest.main()

和set.php是

<?php
echo "Hello";

?>

我得到的输出是Hello1。但我只想在变量$ a中使用Hello,意味着在变量中获取url的输出。

1 个答案:

答案 0 :(得分:3)

对于curl的返回输出形式,设置curl_setopt()

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)