duanquan4451 2014-05-30 13:28
浏览 47
已采纳

yourls api在缩短之前正在执行url

I have installed YOURLS API and its working fine except one problem. Whatever URL I am passing to shorten, its first executing that URL. One of the links is un-subscribe link clicking on which instantly it un-subscribe the member from our mailer. I am using passwordless API call with security token and I am calling yourls-api.php file by file_get_contents function. Here is the code snippet I have written:

$url = urlencode($url);
$api_url = 'http://mydomain.com/yourls/yourls-api.php?signature=593642y63x&action=shorturl&format=json&url='.$url;
$arr_output = json_decode(file_get_contents($api_url), true);   

Can anybody tell me how can I stop YOURLS API to not execute URL before shortening?

  • 写回答

1条回答 默认 最新

  • duangua6912 2014-06-02 06:43
    关注

    Sorry for the delay was bit busy during this weekend.

    Just figured out this morning why you are facing the mentioned problem.

    IN your code:

    $url = urlencode($url);
    $api_url = 'http://mydomain.com/yourls/yourls-api.php?signature=593642y63x&action=shorturl&format=json&url='.$url;
    $arr_output = json_decode(file_get_contents($api_url), true);
    

    you are passing following parameters: signature, action, url and format but the YOURLS api does not count these parameters to be enough it needs one more parameter to be passed along and i.e title

    So you will need to modify your code to include "title" parameter along with all the other parameters you are passing, something like this:

    $url = urlencode($url);
    $api_url = 'http://mydomain.com/yourls/yourls-api.php?title=swati&signature=593642y63x&action=shorturl&format=json&url='.$url;
    $arr_output = json_decode(file_get_contents($api_url), true);
    

    Now, the question arises why not passing the title parameter was causing the URL to be executed? So, this is because if the title parameter is excluded then the YOURLS make an extra HTTP call to the provided URL to fetch the title from that URL.

    Have a good day.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起