Http_Request2 POST request not working

﹥>﹥吖頭↗ 提交于 2019-12-10 19:49:35

问题


Good morning fellows. I'm doing some work with Http_Request2 lib and I'm facing this situation. Im trying to make a POST request to certain URL. If I add the parameters on the query string of the url, i.e.

$request->setUrl('127.0.0.1/something.php?parm1=x&parm2=y');
$request->setMethod(HTTP_Request2::METHOD_POST);

It works fine, but I want to set the parameters with the addPostParameter method:

$request->setUrl('127.0.0.1:8888/something.php');
$request->addPostParameter('parm1', $somevariable);
$request->addPostParameter($some_array_with_parms);

This way doesnt work. The URL indeed is to localhost port 8888.

Is something that I'm missing? Some type of configuration for POST request?

Thanks in advance


回答1:


Here is a sample code:

try {

    $request = new HTTP_Request2('http://127.0.0.1:8888/something.php');
    $request->setMethod(HTTP_Request2::METHOD_POST)
        ->addPostParameter('parm', 'value1') //single param
        ->addPostParameter(array('parmType' => 'val11','parm2' => 'val12')); //multiple
    $response = $request->send()->getBody();

} catch (Exception $exc) {
    echo $exc->getMessage();
}

Note: make sure the port 8888 is open.



来源:https://stackoverflow.com/questions/14382850/http-request2-post-request-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!