Welcome Guest, Not a member yet? Register   Sign In
Error Put method from App in reactNative an RESTAPI CI4
#1

Hello, I am developing a rest api with CI4, and consuming it with an app in reactNative, so far without problems with get methods, now when I want to update a record by sending a PUT it returns an error ( 405 Method Not Allowed)... I am going to clarify certain things: if I try to do the PUT from my client using the local development url everything works correctly, but the question is that my app connects through ngrok since I cannot connect it directly to the localhost, so there if the error of method not allowed ... I've read about cors / heads and others ... but I can't find the solution. I leave some images to verify that the error is not in my code but that somehow CI is blocking the request ... any idea how to solve this? .. thanks in advance

   

   
Reply
#2

If you are on shared hosting, then put, delete verbs may be disabled, I have got the same issue, after switching to cloud all working fine.
Reply
#3

(This post was last modified: 06-14-2021, 11:34 PM by paliz.)

See this

https://codeigniter.com/user_guide/incom...ofing.html

form action="" method="post">
<input type="hidden" name="_method" value="PUT" />
</form>

If you send json you should
{
"_method" :"PUT"
}
Enlightenment  Is  Freedom
Reply
#4

(This post was last modified: 06-15-2021, 12:55 AM by InsiteFX.)

If it is a CORS problem I use this in my .htaccess file in the root with index.php

Code:
    ## For CORS Configuration

    # Add Font Types
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf        .ttf
    AddType application/x-font-opentype  .otf
    AddType application/font-woff        .woff
    AddType application/font-woff2        .woff2

    <IfModule mod_headers.c>
        <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg|svgz|jpg|png|ico|font.css|css|js)$">
            ## un-remark this one for all access and remark out the one below it
            #Header set Access-Control-Allow-Origin "*"
            ## Change this to your url. and https or http
            Header add Access-Control-Allow-Origin: "https://your-domain.com"
            Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
            Header add Access-Control-Allow-Headers: "Upgrade-Insecure-Requests"
        </FilesMatch>
    </IfModule>

    # Remove index.php from URL
    RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    RewriteCond %{THE_REQUEST}              ^[^/]*/index\.php [NC]
    RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

Make sure that you change your-domain.com to your real URL.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(06-14-2021, 10:51 PM)paliz Wrote: See this

https://codeigniter.com/user_guide/incom...ofing.html

form action="" method="post">
    <input type="hidden" name="_method" value="PUT" />
</form>

If you send json you should
{
"_method" :"PUT"
}


Thanks for your help, but I make my request from an app in react I don't have a form to do that ... that is, my call is directly from javascript with axios
Reply
#6

Look i used angular 11 and send json to backend and i add this
{
"_method" :"PUT"
} and other data wll send to backend with put request okay

If multi part form data to should add formdata. Add(_method, put) with files itll send to backend and request must be post http
Enlightenment  Is  Freedom
Reply




Theme © iAndrew 2016 - Forum software by © MyBB