简体   繁体   English

Laravel 通过 API 使用 API 检查数据

[英]Laravel checking data with API through API

I have some data that compressed with gzip in an application from here: app.myaddress.com/data/api/1 .我在以下应用程序中使用 gzip 压缩了一些数据: app.myaddress.com/data/api/1

The data contains several parameters in JSON format like follows:数据包含几个 JSON 格式的参数,如下所示:

{
    "id": 1,
    "data": "abcabcabcabcabc" //this is the compressed data
}

I need to check the compressed data with another 3rd party service, we can just say the address like follows: app2.myaddress.com/check_data/abcabc by API request, but it's needed a header authentication:我需要使用另一个 3rd 方服务检查压缩data ,我们可以通过 API 请求说出如下地址: app2.myaddress.com/check_data/abcabc ,但需要标头身份验证:

{
    "content-type": "application/json",
    "api-key": 123456
}

app2.myaddress.com will return data JSON format like follows: app2.myaddress.com将返回数据 JSON 格式,如下所示:

{
    "name": "hello",
    "address": "australia"
}

What I need to do is just checking a data by accessing URL like: app.myaddress.com/data/api/checked/1 then the controller will process the data include checking through app2.myaddress.com and return the value into app.myaddress.com我需要做的只是通过访问 URL 来检查数据,例如: app.myaddress.com/data/api/checked/1然后控制器将处理数据,包括通过app2.myaddress.com检查并将值返回到app.myaddress.com

Solved by @rafitio :@rafitio解决:

You can use cURL or Guzzle to access both URL inside your function.您可以使用 cURL 或 Guzzle 访问函数内的两个 URL。 Here is the documentation of Guzzle: http://docs.guzzlephp.org/en/stable/request-options.html这是 Guzzle 的文档: http ://docs.guzzlephp.org/en/stable/request-options.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM