我有以下代码
const {
isLoading,
error,
data: calculatorProducts
} = useQuery('fetchSomething', ()=> fetchFunc())
Run Code Online (Sandbox Code Playgroud)
当我访问我的主页时应该调用此函数,但是当从另一个页面返回此路由时,不会触发此请求,并且我没有获取新数据。我想要的是每次像 useEffect 一样调用这个查询
当我尝试从 Strapi API 获取数据时,我从 Next.js 应用程序中获取{statusCode: 400, error: 'Bad Request', message: 'Malicious Path'}. 我的代码如下所示:
import '../styles/globals.css'
import App from "next/app"
import Head from "next/head"
import Link from 'next/link'
import { createContext } from "react";
import { fetchAPI } from "lib/api";
import { getStrapiMedia } from "lib/media"
export const GlobalContext = createContext({})
export default function MyApp({ Component, pageProps }) {
const { global } = pageProps;
console.log(global)
return (
<>
<Head>
<title>{getStrapiMedia(global.siteName)}</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<meta name="description" …Run Code Online (Sandbox Code Playgroud)这是我的代码
app.post("/hi",(req, res)=>{
const schema = Joi.object({
name: Joi.string().min(2).required()
});
const result=schema.validate(req.body);
if(result.error){
res.status(400).send(result.error);
return;
}
console.log(req.body);
});
const port=process.env.PORT || 3000
app.listen(port, ()=>{
console.log("listening on port "+port );
});
Run Code Online (Sandbox Code Playgroud)
它只是在端口 3000 上侦听本地主机并将请求正文记录到控制台中。当我通过邮递员发送任何请求时,它工作正常,除了输出“未定义”。为什么是这样?这是我的代码问题还是我使用 Postman 的问题?
我试图从共享托管服务器请求第三方服务器的 API,所以我没有 root 访问权限,并收到此错误,但是当我在失眠中尝试它时,它正常工作,显然是由于它的原因代理或证书。已经尝试httpsAgent: new https.Agent({ rejectUnauthorized: false })在 axios 请求选项中使用,并尝试过 NODE_TLS_REJECT_UNAUTHORIZED=0,但没有成功。我没有粘贴证书和服务器信息信息,但如果有必要,我可以分享它。这就是我提出请求的方式:
async appInfo(){
var config = {
method: 'get',
url: `${this.url}/api/v2/me/shipment/app-settings`,
headers: {
'Accept': 'application/json',
'Authorization':`Bearer ${this.bearer}`,
'User-Agent': this.user_agent
}
};
var response = await axios(config)
console.log(JSON.stringify(response.data));
}Run Code Online (Sandbox Code Playgroud)
我正在尝试调用 Shiplogic API(基于 AWS),但出现400 Bad Request错误。
我尝试了各种方法来请求 AWS API(例如 S3)的响应,我尝试为 cURL 请求创建自己的签名,现在我正在尝试此代码。
$host = "api.shiplogic.com";
$accessKey = 'AKIA55D****';
$secretKey = 'cx0WDJLNj1Bmn2**';
$requestUrl = 'https://api.shiplogic.com';
$uri = '/tracking/shipments';
$httpRequestMethod = 'GET';
$data = '{"tracking_reference": "M3RPH"}';
require 'AWS/aws-autoloader.php';;
use Aws\Signature\SignatureV4;
use Aws\Credentials\Credentials;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Client\ClientInterface;
$signature = new SignatureV4('execute-api', 'af-south-1');
$credentials = new Credentials($accessKey, $secretKey);
$psr7Request = new Request($httpRequestMethod, $requestUrl.$uri, ["content-type"=>"application/json"], $data);
$client = new Client([$requestUrl, 'timeout' => 30]);
$sr = $signature->signRequest($psr7Request, $credentials);
$response = $client->send($sr);
var_dump($response); …Run Code Online (Sandbox Code Playgroud) 如何在Form方法中访问Request对象?我假设在Form方法中使用ActionHelper以某种方式访问控制器的请求对象,但是为这样的任务编写新类似乎过多了.
或者我应该以某种方式将控制器的请求保存到Zend_Registry并访问表单中的注册表项?
这伤害了我的头脑.在一个函数我有下面的代码.什么伤害了我的头脑是我可以在我的RawUrl中se&id =它应该保持的值同时if语句中的req ["id"]返回null
var req = HttpContext.Current.Request;
string u = req.RawUrl; // --> /pstcm&id=5653999025705172077
d = null;
if (req["id"] != null)
Run Code Online (Sandbox Code Playgroud) 我有一个我们的客户发送了一个涉及我的网站的出版物,但他们使用了错误的地址...他们没有提供页面名称...它看起来像这样:
mywebsite.org/Resources/toolkits/bridging
什么时候应该
mywebsite.org/Resources/toolkits/bridging/default.aspx
有没有办法告诉ASP.NET默认为这个default.aspx,当它看到这种请求或甚至更好,有IIS 7轻松处理这个?这个网站是现场的,所以我想避免在可能的情况下引入代码.
获取内容时遇到问题.我不知道post变量的名称所以我不能这样做
$variable = $_POST['name'];
Run Code Online (Sandbox Code Playgroud)
因为我不知道"名字".我想捕获POST方法发送的所有变量.如何获取$_POST[]数组的键和相应的值?
我建立一个PHP框架,并在其中我有一个解析URL还有一个请求对象$_GET,$_POST和$_FILE超全局变量.
我想鼓励安全的网络习惯,所以我保护数据不受SQL注入等的影响.
为了确保此框架的用户通过请求对象访问安全,干净的数据,我计划unset($_GET, $_POST, $_REQUEST);在解析这些变量后使用.
我将在方法注释中记录这一点,并在框架文档中解释这种情况.
我的问题是:这是否是理想的行为?我没有预料到的潜在陷阱是什么?