菲尔·斯特金休息服务器返回412


Phil Sturgeons Rest Server returning 412

好的,另一个API问题。

在我的Rest Server中,我有以下一个应用程序。

public function hire_get()
{
  echo $_GET['name'];
}

然后我在另一个运行Rest Client 的应用程序中有以下内容

public function __construct()
{
    parent::__construct();
    $this->load->library('rest', array(
        'server' => 'https://mywebsite.com/api/',
    ));
}
public function hireRequest()
{
    $response = $this->rest->post('requests/hire?name=MitchEvans');
    echo $response;
    $this->rest->debug();
}

现在,当我通过web浏览器调用函数hireRequest时,我得到$this->rest->debug()的结果如下:

它得到的是No Response,错误为:The requested URL returned error: 412我在代码412中搜索HTTP请求,它说它是precondition failed error。这是我的网络服务器的问题吗?我该如何解决这个问题?

我认为值得注意的是,如果我直接从网页调用hire_get函数,如下所示:http://www.mywebsite.com/api/requests/hire?name=My Awesome Name,它工作得很好,并与My Awesome Name相呼应,但一旦我试图通过另一个web应用程序访问它,它就会给我错误。

即使我把所有东西都切换到一个帖子,我仍然会收到412错误。

您需要将Rest Client调用从post更改为get,因为您的Rest Server函数是hire_get

如果你想发布数据,你的休息服务器需要改为hire_post

重新引用Rest服务器的GitHub页面:

https://github.com/chriskacerguis/codeigniter-restserver

Accessing parameters is also easy. Simply use the name of the HTTP verb as a method:
$this->get('blah'); // GET param
$this->post('blah'); // POST param
$this->put('blah'); // PUT param

大约四分之一的路下来读我!