如何处理“使用get/head方法”的“请求”不能遇到身体问题。在vuejs?
我在检查一些URL及其状态代码时有问题。我有一个PHP功能
public function checkUrl(Request $request)
{
$curl = curl_init($request->url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return $code;
}
,在VUE中,当我检查它们时,我将其称为
Object.keys(this.items).forEach(key => {
let value = this.items[key];
let checkUrl = value.url + this.usersearch;
fetch('/api/checkurl', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
mode:'cors',
cache:'default',
body: JSON.stringify({url:checkUrl}),
})
“ TypeError:无法构造“请求”:使用get/head方法的请求无法具有身体。 使用方法,帖子工作正常,但是我需要用GET方法检查URL。如果有人知道我在这里做错了什么,我会非常感激。
I have a problem with checking some URLs and their status code. I have a php function
public function checkUrl(Request $request)
{
$curl = curl_init($request->url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return $code;
}
And in Vue I call it like this
Object.keys(this.items).forEach(key => {
let value = this.items[key];
let checkUrl = value.url + this.usersearch;
fetch('/api/checkurl', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
mode:'cors',
cache:'default',
body: JSON.stringify({url:checkUrl}),
})
When I check them I get the Uncaught TypeError: Failed to construct 'Request': Request with GET/HEAD method cannot have body.
With method POST works fine, but I need to get the URLs checked with GET method. If anyone has idea what am I doing wrong here, I would be very grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是在GET请求正文中发送
url
参数,而HTTP协议不允许。获得请求没有身体。而是将其作为URL参数发送:另外,请确保为GET请求配置您的后端路由。
You are sending the
url
param in the body of a GET request, which is not allowed by the HTTP protocol. GET requests don’t have a body. Send it as an URL param instead:Also, make sure your backend route is configured for GET requests.