我写了一些填写登录表单的代码,并通过post方法提交.喜欢:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
);
$this->siteObj = new Zend_Http_Client('http://example.com', $config);
$this->siteObj->setCookieJar();
$this->siteObj->setUri('http://example.com/login');
$this->siteObj->setParameterPost( 'data[User][name]', 'user' );
$this->siteObj->setParameterPost( 'data[User][password]', 'password' );
$response = $this->siteObj->request('POST');
Run Code Online (Sandbox Code Playgroud)
它的工作正常,但有时会发生此错误:
Error in cURL request: name lookup timed out
Error: An Internal Error Has Occurred.
Run Code Online (Sandbox Code Playgroud)
有什么问题?我能做些什么来解决它?
我尝试使用composer安装zf2组件但不能这样做因为composer总是下载所有框架,我做错了什么?
作曲家版本1beccf9
{
...
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"zendframework/zend-http" : "2.0.*"
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在搜索stackoverflow和Google以解决我的问题.
我用Zend Framework创建了两个项目 - Project1而且Project2- 我希望在其中一个项目上实现Web服务.我们的想法是Project1使用POST 向JSON字符串发送并接收一个JSON,其中包含与该变量相关的所有详细信息.现在我已经创建了一个TestController Project2:
public function indexAction(){
$uri = 'http://project1.com/WebService/data';
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
);
$client = new Zend_Http_Client($uri, $config);
$request = $client->request('POST');
print_r($request->getBody());
exit();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码有效.它dataAction从Project1控制器读取并给出一个回显的输出.但是,当我尝试这个:
public function indexAction(){
$uri = 'http://project1.com/WebService/data';
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
);
$client = new Zend_Http_Client($uri, $config);
$data = array(
'userID' => 'TEST TEST',
'value' => …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Zend_Http_Client和POST将数据发送到Google Analytic的收集器.我有一个数组$postParams,包括我的跟踪ID,cid和命中类型,我通过这个数组添加到我的客户端的值setParameterPost().
这是我的行动的相关部分:
$client = new Zend_Http_Client('https://ssl.google-analytics.com/debug/collect');
foreach ($postParams as $postParam => $postValue) {
$client->setParameterPost($postParam, $postValue);
}
$response = $client->request();
Run Code Online (Sandbox Code Playgroud)
调用此脚本时,我收到以下错误:
无法自动处理内容类型''.请使用Zend_Http_Client :: setRawData发送此类内容.
它被抛入_prepareBody()Zend_Http_Client 中的方法中.当我在echo($this->enctype); die();那里添加时,我会收到NULL.
我会添加$client->setEncType();到我的代码但数据很简单.
有谁知道我在这里缺少什么?我真的要用setRawData吗?
提前致谢!
更新:$client->setParameterPost('postParams', $postParams);也不会有效.它会抛出同样的错误.
我正在尝试从Zend Http Client迁移到Guzzle Http Client.我发现Guzzle功能强大且易于使用,但我认为在使用Cookie插件时没有很好的文档记录.所以我的问题是你如何在Guzzle中为你要针对服务器的HTTP请求设置cookie.
使用Zend Client,你可以做一些简单的事情:
$client = new HttpClient($url); // Zend\Http\Client http client object instantiation
$cookies = $request->cookies->all(); // $request Symfony request object that gets all the cookies, as array name-value pairs, that are set on the end client (browser)
$client->setCookies($cookies); // we use the above client side cookies to set them on the HttpClient object and,
$client->send(); //finally make request to the server at $url that receives the cookie data
Run Code Online (Sandbox Code Playgroud)
那么,你如何在Guzzle中做到这一点.我查看了http://guzzlephp.org/guide/plugins.html#cookie-session-plugin.但我觉得这不是直截了当的,也无法理解它.可能有人可以帮忙吗?
我需要调试我的Zend_Http_Client代码,以便我确定我将所有正确的POST字段和标题发送到我的服务器.如何输出将要发送的POST字段列表,甚至输出整个HTTP命令的列表?
我有一个可以通过HTTP或HTTPS访问的URL.我想发送一个最快的HEAD或GET请求并获取响应代码,以便我知道URL是up还是down.
我如何使用Zend_HTTP_Client做到这一点?我使用了get_headers()函数,但在某些远程服务器上它非常慢.我不确定它是否处理HTTPS.
我正在开发一个使用Zend_Http_Client访问远程逻辑的公共站点.客户端适配器中是否有属性/方法可以设置浏览站点的用户的远程地址?
目前正在使用此解决方法,它结合了远程地址和远程useragent.
$client = new Zend_Http_Client();
$client->setConfig(array(
'useragent' => 'Get Remote Address'.'Get User Agent',
));
Run Code Online (Sandbox Code Playgroud)
远程地址是否有特定属性?
您好我使用Zend_Http_Client与适配器Zend_Http_Client_Adapter_Curl,我尝试使用REFERER设置
$client = new Zend_Http_Client('http://www.example.com',array('adapter'=>'Zend_Http_Client_Adapter_Curl');
$client->getAdapter()->setCurlOption('CURLOPT_REFERER','http://www.google.com');
$client->request('POST');
echo $client->getLastRequest();
Run Code Online (Sandbox Code Playgroud)
在我的请求中,我看到除REFERER头之外的各种标头设置?它可以使用$ client-> setHeaders('Referer',$ url); 但我也在寻找更好的方法.谢谢.
使用Zend Framework Http客户端,如何从每个请求获取http响应/服务器代码?我的身体很好,但响应代码也很好.
zend-http-client ×10
php ×8
curl ×3
post ×2
composer-php ×1
cookies ×1
debugging ×1
dns ×1
httpclient ×1
referer ×1
symfony ×1
symfony-2.1 ×1
web-services ×1