我正试图从一个网站获取一些国家名称。该网站的网址以https开头,因此我无法废弃数据。请给我一些解决方案。
这是我的代码:
import {Component} from '@angular/core';
import {NavController, NavParams, Toast} from 'ionic-angular';
import {Http, URLSearchParams} from '@angular/http';
import {AppSettings} from '../../appSettings';
import {Subject} from 'rxjs/Subject';
@Component({
templateUrl: 'build/pages/video/video.html'
})
export class VideoPage {
_postMPCHC: any= new Subject();
constructor(private http: Http, private nav: NavController) {
this.defineHttp();
}
defineHttp() {
var sub = this._postMPCHC.switchMap((x: string) => {
let params: URLSearchParams = new URLSearchParams();
params.set('token', AppSettings.API_TOKEN);
params.set('prog', 'mhz');
params.set('prog', 'mpchc');
params.set('action', x);
return this.http.get(AppSettings.API_ENDPOINT, { search: params })
}).timeout(5000, new Error('timeout exceeded')).subscribe(x => { },
error => {
let toast = Toast.create({
message: 'Server response: ' + <any>error,
duration: 3000,
position: 'middle'
});
this.nav.present(toast);
})
}
}
收到此错误:$curl = curl_init('https://testing.co/india');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if (curl_errno($curl)) {`enter code here`
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$regex = '/<a class="startup-link">(.*?)<\/a>/s';
if (preg_match($regex, $page, $list))
echo $list[0];
else
print "Not found";
答案 0 :(得分:0)
今天我正在解决这个问题,我开始了解它。
请参阅。以下代码对我有用。
// Set so curl_exec returns the result instead of outputting it.<br/>
$url = "https://www.google.co.in/?gws_rd=ssl";<br/>
$ch = curl_init();<br/>
curl_setopt($ch, CURLOPT_URL, $url);<br/><br/>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br/>
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<br/>
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);<br/>
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "GeoTrustGlobalCA.crt");
<br/>
// Get the response and close the channel.<br/>
$response = curl_exec($ch);<br/>
$link = fopen("data.txt","w+");<br/>
fputs($link,$response);<br/>
fclose($link);<br/>
curl_close($ch);<br/>
你有通过证书.. 在Mozilla Firefox上,您可以获得一个信息图标。然后单击Security选项卡,然后查找View certificate。单击Details选项卡。 请参阅证书层次结构部分。点击最顶部的标签,看下面有一个选项为EXPORT。导出该证书并将CA证书保存到所选位置,确保选择X.509证书(PEM)作为保存类型/格式。
e.g。
curl_setopt($ ch,CURLOPT_CAINFO,getcwd()。“GeoTrustGlobalCA.crt”);
现在保存并运行..您将获得数据..
答案 1 :(得分:-1)
使用
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false)