[英]Cannot get "images" net::ERR_CONNECTION_REFUSED (Gitpod)
On Gitpod , my NextJS frontend is trying to fetch the list of objects which contain "product names" , "prices" and "images" from my Django Rest API backend .在Gitpod 上,我的 NextJS 前端试图从我的 Django Rest API 后端获取包含“产品名称” 、 “价格”和“图像”的对象列表。 Then, my NextJS frontend can get the list of objects which contain "product names" and "prices" but not "images" so my NextJS frontend cannot get only "images" as shown below:
然后,我的 NextJS 前端可以获取包含“产品名称”和“价格”但不包含“图像”的对象列表,因此我的 NextJS 前端不能仅获取“图像” ,如下所示:
( "product names" such as "boots 4", "boots 3"... and "prices" such as "£12.10", "£10.50"... are displayed but not "images" ) (显示“靴子 4”、“靴子 3”等“产品名称”以及“£12.10”、“£10.50”等“价格”,但不显示“图片” )
This is my desired output with "product names" , "prices" and "images" :这是我想要的 output,带有“产品名称” 、 “价格”和“图片” :
On Gitpod , both my NextJS frontend on port 3000 open (private) and my Django Rest API backend on port 8000 open (private) are running:在Gitpod上,我在端口 3000 打开(私有)的 NextJS 前端和我在端口 8000 打开(私有)的后端 Django Rest API都在运行:
And my NextJS frontend uses this Rest API call with "localhost" as shown below to get the list of objects which contain "product names" , "prices" and "images" :我的 NextJS 前端使用 Rest API 调用“localhost” ,如下所示,以获取包含“产品名称” 、 “价格”和“图像”的对象列表:
http://localhost:8000/api
And, there are these errors:而且,还有这些错误:
3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987
3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987
GET http://localhost:8000/media/images/paid.png.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987获取 http://localhost:8000/media/images/paid.png.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987
GET http://localhost:8000/media/images/size.png.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987获取 http://localhost:8000/media/images/size.png.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987
GET http://localhost:8000/media/images/download.jpg.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987获取 http://localhost:8000/media/images/download.jpg.net::ERR_CONNECTION_REFUSED 3000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/:987
GET http://localhost:8000/media/images/02173_l.jpg.net::ERR_CONNECTION_REFUSED获取 http://localhost:8000/media/images/02173_l.jpg.net::ERR_CONNECTION_REFUSED
Actually, I solved these errors above by using this Rest API call with my Gitpod domain as shown below to get the list of objects:实际上,我通过使用 Rest API 调用我的 Gitpod 域来解决上面的这些错误,如下所示,以获取对象列表:
https://8000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/api
But other error occurs as shown below:但是出现其他错误,如下所示:
Server Error
FetchError: invalid json response body at https://8000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/api reason: Unexpected end of JSON input
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
pages/index.js (73:16) @ async getStaticProps
71 | export async function getStaticProps() {
72 | const res = await fetch("https://8000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/api");
> 73 | const posts = await res.json();
| ^
74 |
75 | // const ress = await fetch("http://127.0.0.1:8000/api/category/");
76 | // const categories = await ress.json();
Actually, this Rest API call with my Gitpod domain is correct because with this Rest API call, I can get the list of objects on Postman from my Django Rest API backend on Gitpod : Actually, this Rest API call with my Gitpod domain is correct because with this Rest API call, I can get the list of objects on Postman from my Django Rest API backend on Gitpod :
https://8000-gitpodio-templatetypescr-tqzkjl97w1d.ws-us33.gitpod.io/api
Are there any solutions to solve this error and get the list of objects which contain "product names" , "prices" and "images" ?是否有解决此错误并获取包含“产品名称” 、 “价格”和“图像”的对象列表的解决方案?
You should make the port 8000 for your Django Rest API backend "public" to get the list of objects which contain "product names" , "prices" and "images" :您应该将8000 端口设置为 Django Rest API 后端“public” ,以获取包含“product names” 、 “prices”和“images”的对象列表:
Finally, you can get the list of objects which contain "product names" , "prices" and "images" :最后,您可以获得包含“产品名称” 、 “价格”和“图片”的对象列表:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.