我在CURL响应方面遇到问题。每当我尝试执行curl请求时,我都会以不可读的格式获得响应。
�)K���m!`����]mO�@������1���g��^�ګ�6���?]8�"wP�����gf��E�)��`�fgg�ea�1{�:���k�����ŰVC��/�2���\��sA�:��<i��f��я�n�5כY�Y������Ƀ�%��X� �[&9��P\A��pk9-��Uw��2|t���~�V��fYjC��!u���R�5��w��);եЕ4�����YDe�+T�w��I�� /l�>�S�I�/Ɯm@�`d]1��@�`
下面我提供了我的代码:
$header = array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 3000";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt(self::$curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
curl_setopt(self::$curl, CURLOPT_HTTPHEADER, $header);
curl_setopt(self::$curl,CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt(self::$curl,CURLOPT_COOKIEFILE, $cookieJar);
curl_setopt(self::$curl,CURLOPT_AUTOREFERER, true);
curl_setopt(self::$curl,CURLOPT_FOLLOWLOCATION, true);
curl_setopt(self::$curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt(self::$curl,CURLOPT_SSL_VERIFYPEER, false);
我要抓取的网站是https://www.boots.com/
当我在其他网站(例如https://www.bbc.co.uk/news)上尝试时,效果很好。
如果要添加更多内容,请询问。
谢谢
答案 0 :(得分:0)
我一开始就添加了这些附加标题,从而为我解决了这个问题。
serviceCollection
.AddIdentityCore<MyUser>(identityOptions =>
{
identityOptions.SignIn.RequireConfirmedEmail = false;
})
.AddUserStore<MyUserStore>()
.AddSignInManager<SignInManager<MyUser>>();
serviceCollection.AddAuthentication(IdentityConstants.ApplicationScheme)
.AddCookie(IdentityConstants.ApplicationScheme, options =>
{
options.SlidingExpiration = true;
})
.AddGoogle(googleOptions =>
{
this.Configuration.Bind("OAuth2:Providers:Google", googleOptions);
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub", "string");
})
.AddExternalCookie();