dousui6488 2018-04-13 08:20 采纳率: 100%
浏览 5550
已采纳

怎么在Curl中指定传出端口?

亲爱的,我正在尝试从Apache Server执行php curl调用,但我需要指定特定端口(出站)的请求,或者至少知道Apache使用的输出端口的范围。因为目标服务器位于一个严格的防火墙后面,它只允许一个IP和一个特定端口通过。希望得到你的帮助。
  • 写回答

1条回答 默认 最新

  • dtjxhf595733 2018-04-13 08:29
    关注

    You could try this. i think this option CURLOPT_LOCALPORT is what you're looking for

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://example.com/");
    curl_setopt($ch, CURLOPT_PORT, [destinationport]);
    
    curl_setopt($ch, CURLOPT_LOCALPORT, [sourceport]);
    
    $output = curl_exec($ch);
    curl_close($ch);      
    print($output);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?