简体   繁体   English

从Rest API从Android进行HTTP调用

[英]Http Call from android from Rest API

How do I get rest api data that I created using Django's rest framework? 如何获取使用Django的rest框架创建的rest api数据? Also just for the information I am not being able to access this link from my android phone browser either so quiet obviously if I do a volley /http reqest it won't do anything. 也只是为了提供信息,我无法从我的android手机浏览器访问此链接,或者如果我执行凌空/ http请求显然很安静,那么它什么也不会做。

在此处输入图片说明

To request rest Apis in android you can use a library called “RETROFIT” Please checkout their documentation and you can see a lot of tutorials on retrofit. 要在Android中请求休息Apis,您可以使用一个名为“ RETROFIT”的库。请查看其文档,然后您会看到很多有关改造的教程。

Also, if you haven't deployed your drf based django project to a production/live server you will not be able to request and receive responses from your apis, 另外,如果您尚未将基于drf的django项目部署到生产/实时服务器,则将无法从api请求和接收响应,

Also another tool for testing your apis is POSTMAN. 另一个测试API的工具是POSTMAN。 Its a chrome app which can request and show you responses from apis. 它是一个Chrome应用,可以请求并向您显示来自api的响应。

Since you are trying to request using volley and it isnt working, it must be that you havent deployed the django app and you are still using a development server, 由于您尝试使用排球请求并且无法使用,因此必须确保您尚未部署django应用,并且仍在使用开发服务器,

In that case Run the server using 在这种情况下,使用

Python manage.py runserver 0.0.0.0:8000

And then find your machines ip address, using 然后找到你的机器的ip地址,使用

ifconfig or ipconfig (depends on ur OS)

And once you get it, use that ip as your base url for the api and connect your android phone used for testing the api into the same network where your machine running django is connected to. 并且一旦获得它,就使用该ip作为api的基本URL,并将用于测试api的android手机连接到运行django的计算机所连接到的同一网络中。

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

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