小编Mik*_*e B的帖子

ZF2卷曲不发送帖子值

我试图使用本机Zend Framework 2 http\curl库,我可以让它将请求发送到远程应用程序我只是无法让它到POST值.

这是我的代码,显示了2个示例,第一个是使用本机PHP curl,它工作正常,第二个是使用ZF2 http\curl库,它不传递任何POST参数.

示例1(本机PHP库)

    $url = $postUrl . "" . $postUri;

    $postString = "username={$username}&password={$password}";

    //This works correctly using hte native PHP sessions
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    var_dump($output); //outputs the correct response from the remote application
Run Code Online (Sandbox Code Playgroud)

示例2(ZF2库使用)

    $url = $postUrl . "" . $postUri;

    $postString = "username={$username}&password={$password}";

    //Does not work using ZF2 method!
    $request = new Request;

    $request->setUri($url);
    $request->setMethod('POST');

    $adapter = new Curl;

    $adapter->setOptions([
        'curloptions' …
Run Code Online (Sandbox Code Playgroud)

php zend-framework2

2
推荐指数
2
解决办法
5876
查看次数

标签 统计

php ×1

zend-framework2 ×1