PHP Post data with Fsockopen

前端 未结 10 1546
梦如初夏
梦如初夏 2020-12-01 15:20

I am attempting to post data using fsockopen, and then returning the result. Here is my current code:



        
10条回答
  •  隐瞒了意图╮
    2020-12-01 15:44

    Curl is too heavy in some case, to use post_to_host():

    //GET:
    $str_rtn=post_to_host($str_url_target, array(), $arr_cookie, $str_url_referer, $ref_arr_head, 0);
    
    //POST:
    $arr_params=array('para1'=>'...', 'para2'=>'...');
    $str_rtn=post_to_host($str_url_target, $arr_params, $arr_cookie, $str_url_referer, $ref_arr_head);
    
    //POST with file:
    $arr_params=array('para1'=>'...', 'FILE:para2'=>'/tmp/test.jpg', 'para3'=>'...');
    $str_rtn=post_to_host($str_url_target, $arr_params, $arr_cookie, $str_url_referer, $ref_arr_head, 2);
    
    //raw POST:
    $tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));
    $arr_params=array('para1'=>'...', 'para2'=>'...');
    file_put_contents($tmp, json_encode($arr_params));
    $arr_params=array($tmp);
    $str_rtn=post_to_host($str_url_target, $arr_params, $arr_cookie, $str_url_referer, $ref_arr_head, 3);
    
    //get cookie and merge cookies:
    $arr_new_cookie=get_cookies_from_heads($ref_arr_head)+$arr_old_cookie;//don't change the order
    
    //get redirect url:
    $str_url_redirect=get_from_heads($ref_arr_head, 'Location');
    

    post to host php project location: http://code.google.com/p/post-to-host/

提交回复
热议问题