问题描述
我们有一个API,我们正在通过React Native进行查询.
获取,在我们的应用程序或Postman中完美地发布请求工作.
删除在应用程序上不起作用,,但同样的请求与Postman一起使用.
什么是怪异的是:
如果我们使用Django或Postman删除资源,则在电话上我们的应用程序中的请求完全相同,将为我们提供404响应,并告诉我们确实已删除.
这意味着我们应用程序的呼叫应该起作用,因为我们从API中得到答案!
因此,基本上,删除无法从应用程序中使用,但是如果我们从其他地方删除资源,它的作用似乎对真实.
我们从两台不同的手机进行了测试,以防万一... 我们正在使用Expo.
我们删除请求的示例:
https://apiurl/reservations/id_num :{" accept":" application/json"," content-type":" application/json"," x-app-token":" blablatoken","授权":" jwt blablasuperlongtoken"}}
更新: Mattyk14问的问题很好,我们得到200个回应,这应该是我们的回应. 我们在这条路上进行了调查,但似乎找不到任何东西.
我们正在使用AXIO重建API,因为我们找不到东西,我们会检查.
推荐答案
找到了错误!
我们需要在API URL的末端添加尾斜线. django如果没有拖延斜线,将您的删除请求自动将您的删除请求转换为GET请求. 感谢您的评论Matty和Arman.
问题描述
We have an API that we are querying through React Native.
GET, POST request work flawlessly either in our app or in Postman.
DELETE doesn't work on the App, but the same request works with Postman.
What is even weirder is that :
If we delete the resource either with Django or Postman, making the exact same request from our app on the phone will give us a 404 response, telling us that indeed, it was deleted.
Which means that the call from our app is supposed to work since we get an answer from the API!
So, basically, the DELETE doesn't work from the app but if we delete the resource from elsewhere, it acts as if it works for real.
We tested it from two different phones, just in case... And we are using Expo.
Example of our DELETE request :
https://apiurl/reservations/id_num {"method":"DELETE","headers":{"Accept":"application/json","Content-Type":"application/json","X-App-Token":"blablatoken","Authorization":"JWT blablasuperlongtoken"}}
UPDATE: The question asked by MattyK14 was good, we get a 200 response which is supposed to be our GET response. We investigated on this path but can't seem to find anything.
We are rebuilding the API using Axios as we can't find a thing and we will check.
推荐答案
FOUND THE ERROR!
We needed to add a trailing slash at the end of the API URL. Django automatically transforms your DELETE request into a GET request if it doesn't get a trailing slash. Thank you for your comments Matty and Arman.