我想在我的octobercms后端使用CURL请求从其他网站获取一些数据(HTML)。我不知道该怎么做。任何人都可以帮助我吗?
答案 0 :(得分:1)
OctoberCms提供卷曲包装类Http
https://github.com/octobercms/library/blob/master/src/Network/Http.php
Http::get('http://octobercms.com');
Http::post('...');
Http::delete('...');
Http::patch('...');
Http::put('...');
Http::options('...');
$result = Http::post('http://octobercms.com');
echo $result; // Outputs: <html><head><title>...
echo $result->code; // Outputs: 200
echo $result->headers['Content-Type']; // Outputs: text/html; charset=UTF-8
Http::post('http://octobercms.com', function($http){
// Sets a HTTP header
$http->header('Rest-Key', '...');
// Set a proxy of type (http, socks4, socks5)
$http->proxy('type', 'host', 'port', 'username', 'password');
// Use basic authentication
$http->auth('user', 'pass');
// Sends data with the request
$http->data('foo', 'bar');
$http->data(['key' => 'value', ...]);
// Disable redirects
$http->noRedirect();
// Check host SSL certificate
$http->verifySSL();
// Sets the timeout duration
$http->timeout(3600);
// Write response to a file
$http->toFile('some/path/to/a/file.txt');
// Sets a cURL option manually
$http->setOption('CURLOPT_SSL_VERIFYHOST', false);
});
答案 1 :(得分:0)
首先从此处安装GuzzleHttp,找到所有详细信息: https://github.com/guzzle/guzzle
然后将其包含在Controller或组件中:
func SetEarSepeakerOn()
{
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.none)
} catch _ {
}
}
然后您可以编写类似以下示例代码的代码:
use GuzzleHttp\Client;