我通过PHP使用curl来获取网址.我成功地下载了页面,标题和所有内容.但是,任何页面返回的cookie都不会保存到指定的文件中.我已经检查了权限等,似乎没有什么不寻常的.我开始认为我的代码中存在某些问题.
$get_cookie_page = 'http://www.google.ca';
echo curl_download($get_cookie_page);
function curl_download($Url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$http_headers = array(
'Host: www.google.ca',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
'Accept: */*',
'Accept-Language: en-us,en;q=0.5',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
如果对类中的未定义方法进行调用,则魔术方法__call可以拦截该调用,因此我可以按照我认为合适的方式处理这种情况:http: //www.php.net/manual/en/language.oop5 .overloading.php#language.oop5.overloading.methods
在php中是否提供了任何机制,我可以使用全局范围内的函数执行相同的操作.最好用代码说明这一点:
<?php
function return_some_array(){
$a = array();
//Do stuff to array
return array();
}
// Now i call the function like so:
$give_me_array = return_some_array();
// But sometimes I want the array to not contain zeroes, nulls etc.
// so I call:
$give_me_array_filtered = return_some_array_filtered();
// But i haven't defined return_some_array_filtered() anywhere.
// Instead I would like to do something like so:
function __magic_call($function_name_passed_automatically){
preg_match('/(.*)_filtered$/', $function_name_passed_automatically, $matches);
$function_name_that_i_defined_earlier_called_return_some_array = $matches[1];
if($matches){
$result = call_user_func($function_name_that_i_defined_earlier_called_return_some_array);
$filtered …
Run Code Online (Sandbox Code Playgroud) 我有一个带有链接的html测试页面:
<a href="customprotocol:information-from-browser">Link.</a>
Run Code Online (Sandbox Code Playgroud)
如果我在Safari中打开它并单击链接,处理应用程序(自定义应用程序)将正确打开.
但是,当我在谷歌浏览器中打开此页面并单击该链接时,该应用程序无法打开.
单击的链接会触发GET请求,但它的状态会被取消.整个请求在网络检查器中以红色显示.
我想也许Chrome出于安全原因这样做,并默认阻止未注册的自定义URL方案.为了解决这个问题,我在html页面添加了一些javascript(来自这个问题):
window.location.assign("customprotocol:");
Run Code Online (Sandbox Code Playgroud)
弹出一个对话框,询问用户是否想要将customprotocol:与app相关联.
即使在按下OK并因此设置chrome识别的customprotocol:handler之后,该链接仍然无法启动应用程序.它仍然是取消的请求.
为什么是这样?如何在Google Chrome中使用此功能?
注1:AFAIK,我的所有软件都更新到最新版本.
注意2:取消的请求没有响应和预览信息.在时间安排下,请求显示为停滞不前.
可能重复:
var var fn = function(){...}和var fn = function foo(){...}是否有所不同?
从这里
我知道声明函数和将它们声明为变量之间存在差异.
但目前尚不清楚以下两者之间是否存在任何差异:
var func_name = function(param, param1){...};
Run Code Online (Sandbox Code Playgroud)
和:
var func_name = function func_name(param, param1){...};
Run Code Online (Sandbox Code Playgroud)
它们完全相同吗?
如何在class_eval块中定义类变量?我有以下内容:
module Persist
def self.included(base)
# base is the class including this module
base.class_eval do
# class context begin
@@collection = Connection.new.db('nameofdb').collection(self.to_s.downcase)
def self.get id # Class method
#...
end
end
end
# Instance methods follow
def find
@@collection.find().first
#...
end
end
class User
include Persist
end
class Post
include Persist
end
Run Code Online (Sandbox Code Playgroud)
User和Post类都显示:get
在使用User.methods
或时内省时Post.methods
.这是有道理的,因为它们是在class_eval的上下文中定义的,正是我需要的.类似地,该方法:find
显示为各个类的instance_method.
但是,我认为是类变量,即@@collection
结果是模块级class_variable.当我反思User.class_variables
或者Post.class_variables
,他们打开了空.然而Persist.class_variables
节目:@@collection
.
这怎么可能?不是class_eval
类的块内的上下文.所以不应该@@collection
在类而不是模块上定义变量?
此外,值@@collection
始终是包含它的最后一个类的名称.因此,在这种情况下,它始终是"帖子",而不是"用户".我认为这是因为它是一个模块级变量,它会在每个包含上发生变化.它是否正确? …
我写了一个宏来做多个嵌套循环.我知道还有其他设施可以做到这一点,但我正在努力学习如何编写宏,这似乎是一个很好的用例.它也有效(有点):
(defmacro dotimes-nested (nlist fn)
(let ((index-symbs nil)
(nlist (second nlist))) ;remove quote from the beginning of nlist
(labels
((rec (nlist)
(cond ((null nlist) nil)
((null (cdr nlist))
(let ((g (gensym)))
(push g index-symbs)
`(dotimes (,g ,(car nlist) ,g)
(funcall ,fn ,@(reverse index-symbs)))))
(t (let ((h (gensym)))
(push h index-symbs)
`(dotimes (,h ,(car nlist) ,h)
,(rec (cdr nlist))))))))
(rec nlist))))
Run Code Online (Sandbox Code Playgroud)
运行:
(macroexpand-1 '(dotimes-nested '(2 3 5)
#'(lambda (x y z) (format t "~A, ~A, ~A~%" x y z))))
Run Code Online (Sandbox Code Playgroud)
输出:
(DOTIMES …
Run Code Online (Sandbox Code Playgroud) 如何在do循环中绑定从函数返回的多个值?以下显然是非常错误的,但这可能是这样的吗?
(do (((x y z) (3-val-fn) (3-val-fn)))
((equal y 'some-val) y)
(values x y z))
Run Code Online (Sandbox Code Playgroud)
或者也许有一种方法可以使用多值绑定来做到这一点?
这是我正在编写的一个函数,它将根据起始值,结束值和下一个函数生成一个数字列表.
(defun gen-nlist (start end &optional (next #'(lambda (x) (+ x 1))))
(labels ((gen (val lst)
(if (> val end)
lst
(cons val (gen (next val) lst)))))
(gen start '())))
Run Code Online (Sandbox Code Playgroud)
但是当它进入SBCL repl时,我得到以下警告:
; in: DEFUN GEN-NLIST
; (SB-INT:NAMED-LAMBDA GEN-NLIST
; (START END &OPTIONAL (NEXT #'(LAMBDA (X) (+ X 1))))
; (BLOCK GEN-NLIST
; (LABELS ((GEN #
; #))
; (GEN START 'NIL))))
;
; caught STYLE-WARNING:
; The variable NEXT is defined but never used.
; (NEXT VAL)
;
; …
Run Code Online (Sandbox Code Playgroud) 在CCL顶级,运行:
(make-socket :LOCAL-PORT 6666 :LOCAL-HOST "127.0.0.1")
Run Code Online (Sandbox Code Playgroud)
要么
(make-socket :LOCAL-PORT 6666 :LOCAL-HOST (lookup-hostname "localhost"))
Run Code Online (Sandbox Code Playgroud)
输出以下内容:
> Error: There is no applicable method for the generic function:
> #<STANDARD-GENERIC-FUNCTION CCL::SOCKADDR #x30200043F91F>
> when called with arguments:
> (NIL)
> While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD (T)>, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Try calling it again
> Type :? for other options.
Run Code Online (Sandbox Code Playgroud)
我无法理解错误(CL的新内容).这是什么意思?我做错了什么?
我有点矢量- #*10010010001001...
我想使用READ-BYTE从向量中读取八位字节。但是它需要一个二进制流对象。
我似乎不知道该怎么做。我尝试使用WRITE-SEQUENCE从简单向量(从位向量转换)中获取新流:
(WRITE-SEQUENCE (map 'array #'identity #*10010010...) *standard-output*)
Run Code Online (Sandbox Code Playgroud)
但它抱怨期望的类型必须是CHARACTER。
(我正在使用Clozure Common Lisp。)
我究竟做错了什么?
(请不要建议使用flexi-streams作为答案。我不打算为一件小事情添加一个全新的库。)
common-lisp ×5
php ×2
ccl ×1
curl ×1
javascript ×1
macos-sierra ×1
macros ×1
mongodb ×1
ruby ×1
sockets ×1
url ×1
vector ×1