PHP 的 curl 发 post 请求时老是中断,大伙帮忙看看问题出哪儿了 - V2EX
zhangxu128
V2EX    PHP

PHP 的 curl 发 post 请求时老是中断,大伙帮忙看看问题出哪儿了

  •  
  •   zhangxu128 Feb 12, 2020 3232 views
    This topic created in 2284 days ago, the information mentioned may be changed or developed.

    最近想学习一下旷世的 face++人脸识别,参照文档用 php 写了个脚本,传本地的照片上去测试时发现老是不成功,研究了好久才发现 curl 函数进行 post 请求不成功,试了好多办法也没法正常使用。。。

    <?php function curl($image){ $fp = fopen(dirname(__FILE__).'/errorlog.txt', 'a'); $ch = curl_init(); $post_data = array( 'api_key'=>'key', 'api_secret'=>'secret', 'image_file' => "$image" ); print_r($post_data); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_STDERR, $fp); //curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch,CURLOPT_BINARYTRANSFER,true); curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_URL, "https://api-cn.faceplusplus.com/facepp/v3/detect"); $info= curl_exec($ch); curl_close($ch); print_r($info); return $info; } $image='@image.jpg'; $re=curl($image); print_r($re); ini_set("max_execution_time", 300); 

    附 curl 的日志如下

    Host: api-cn.faceplusplus.com User-Agent: Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) Accept: */* Accept-Encoding: gzip, deflate Content-Length: 19061 Content-Type: multipart/form-data; boundary=------------------------a3ed34acf8fa0825 * Connection state changed (MAX_CONCURRENT_STREAMS == 128)! < HTTP/2 400 < server: Tengine < date: Tue, 11 Feb 2020 16:24:57 GMT < content-type: application/json; charset= < content-length: 157 * HTTP error before end of send, stop sending < * Connection #0 to host api-cn.faceplusplus.com left intact 
    stabc
        1
    stabc  
       Feb 12, 2020
    这种类型的应用还是别用 PHP 了吧
    zhangxu128
        2
    zhangxu128  
    OP
       Feb 12, 2020
    已解决,使用了 curl_file_create 函数来创建文件上传对象。
    zhangxu128
        3
    zhangxu128  
    OP
       Feb 12, 2020
    @stabc 有在考虑 用 php 只是因为用着顺手 23333
    About     Help     Advertise     Blog     API     FAQ     Solana     5890 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 06:34 PVG 14:34 LAX 23:34 JFK 02:34
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86