- 查看mapping:
1curl -XGET '127.0.0.1:9200/【your-index】/_mapping' - 为现有mapping添加新属性:
123//给tags添加 age 属性:curl -X PUT 'http://127.0.0。1:9200/【your-index】/_mapping/【your-type-if-exists】' -H 'content-type:application/json' -d '{"properties":{"tags":{"type":"object","properties":{"age":{"type":"long"}}}}}'
3. 迁移旧index的数据到新index:
1curl -X POST 'http://127.0.0.1:9200/_reindex' -H 'content-type:application/json' -d '{"source":{"index":"【your-old-index】"},"dest":{"index":"【your-new-index】"}}'
4. 删除index:
1curl -X DELETE 'http://127.0.0.1:9200/【your-index】'
标签:curl
curl请求https时不验证证书
若用curl请求https的URL,默认是要求指定证书的,若不想验证证书,可以添加以下选项:
1 2 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); |
【参考:http://happyliu.blog.51cto.com/501986/1610974/】
PHP使用curl上传文件时要注意的@事情
PHP5.5后,使用CURL传文件不能使用@写法,要改用 CURLFile
【参考:https://segmentfault.com/a/1190000000725185】
会用到的函数
一、黑名单过滤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
function is_spam($text, $file, $split = ':', $regex = false){ $handle = fopen($file, 'rb'); $contents = fread($handle, filesize($file)); fclose($handle); $lines = explode("n", $contents); $arr = array(); foreach($lines as $line){ list($word, $count) = explode($split, $line); if($regex) $arr[$word] = $count; else $arr[preg_quote($word)] = $count; } preg_match_all("~".implode('|', array_keys($arr))."~", $text, $matches); $temp = array(); foreach($matches[0] as $match){ if(!in_array($match, $temp)){ $temp[$match] = $temp[$match] + 1; if($temp[$match] >= $arr[$word]) return true; } } return false; } $file = 'spam.txt'; $str = 'This string has cat, dog word'; if(is_spam($str, $file)) echo 'this is spam'; else echo 'this is not spam'; |
1 2 3 4 |
ab:3 dog:3 cat:2 monkey:2 |
微信接口_curl_error_28_超时问题
在使用微信API接口时,若curl返回错误码为28,超时。则考虑以下几点:
a. 是否存在跨运营商访问的情况,详见网络超时的定位
可以ping api.mch.weixin.qq.com查询对应的解析IP
通过访问ip.qq.com获取取口IP,也可以根据商户侧服务器的外网IP确认
b. 是否使用的阿里云主机
由于阿里云使用的BGP,需要确认解析出来的IP是否为182.254.44.159,否则需要调整DNS设置,使用阿里本身的DNS服务器
c. 是否使用curl库访问
需要指定参数使用ipv4,具体可参考http://www.jb51.net/article/39788.htm
d. 确认java程序使用的HttpClient的版本是否<=4.3.4
可升级HttpClient到4.3.6版本
参考:https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=11_2
微信开发_curl_errno_58错误
在使用微信支付API时,若curl返回的错误代码为58,一般与SSL安全策略有关。使用curl时,需指定使用SSL高版本参数信息:
1 |
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
注意,使用以上信息要求,php版本不低于5.2,curl版本不低于7.21
参考:
https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1414562353&version=11&lang=zh_CN
https://binsee.github.io/wechat-php-sdk/2014/201411032325/
使用curl抓取防盗链网站资源
场景:
使用curl获取网页资源,并做进一步内容分析,但当网页启用防盗链功能时,诸如图片内容可能会获取失败。
解决:
在使用curl时,添加头部参数,模拟搜索引擎的蜘蛛爬虫即可。
相关代码:
1 2 3 4 5 6 7 8 9 10 11 |
function baiduSpider($url,$reffer){ $ch = curl_init(); $user_agent = “Baiduspider+(+http://www.baidu.com/search/spider.htm)”;//这里模拟的是百度蜘蛛 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $reffer);//这里写一个来源地址,可以写要抓的页面的首页 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); $temp=curl_exec($ch); return $temp; } |
【参考:】http://m.blogchina.com/blog/view/uname/gaojohn/bid/1257804
微信api——素材管理(上传多媒体文件)
介绍:
使用微信官方提供的API接口,实现上传多媒体文件或素材管理。
PHP实现方式:
1 2 3 4 5 6 7 8 9 10 11 |
$file = '@D:\hello.jpg'; //或者 $file = '@/var/www/hello.jpg' $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE';//其中,ACCESS_TOKEN和TYPE要根据具体情况填写,详细参考下面的【参考】链接 $ch = curl_init(); $data = array('media'=>$file); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $s = curl_exec ($ch); curl_close($ch); var_dump($s); |
备注:注意$file参数,文件的绝对路径前要加符号’@’。
【参考:】
http://mp.weixin.qq.com/wiki/5/963fc70b80dc75483a271298a76a8d59.html
http://www.tuicool.com/articles/JzURz2
10 awesome things to do with cURL
Acknowledgments
New to cURL? If yes, check out the following articles to learn the purposes and basics of cURL/libcurl.
Please note that some of the techniques shown here can be used for “blackhat” methods. The goal of this article is only educationnal, please do not use any of the snippets below for illegal stuff. 继续阅读“10 awesome things to do with cURL”
使用PHP CURL的POST数据
curl 是使用URL语法传送文件的工具,支持FTP、FTPS、HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP。curl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传,kerberos、基于HTT格式的上传、代理、cookie、用户+口令证明、文件传送恢复、http代理通道和大量其他有用的技巧。
原来php默认并不进行此项功能的扩展,但还是有的,只是没有让它生效罢了。打开PHP安装目录,搜索以下三个文件 ssleay32.dll、libeay32.dll和 php_curl.dll,一一拷贝到系统目录下的system32文件夹下,修改php.ini文件,找到;extension= php_curl.dll行,去掉前面的;号,保存,重启服务器。
下面举几个例子。