Http_Request2 POST请求不起作用 [英] Http_Request2 POST request not working
本文介绍了Http_Request2 POST请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
各位早上好.我正在使用Http_Request2 lib做一些工作,我正面临这种情况.我正在尝试向某些URL发出POST请求.如果我在网址的查询字符串上添加参数,即
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);
它工作正常,但我想使用addPostParameter方法设置参数:
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);
这种方式行不通.该URL确实指向本地主机端口8888.
This way doesnt work. The URL indeed is to localhost port 8888.
我缺少什么吗?某种类型的POST请求配置?
Is something that I'm missing? Some type of configuration for POST request?
预先感谢
推荐答案
以下是示例代码:
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();
}
注意:确保端口8888已打开.
Note: make sure the port 8888 is open.
这篇关于Http_Request2 POST请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文