CodeIgniter Forums
Error Put method from App in reactNative an RESTAPI CI4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Error Put method from App in reactNative an RESTAPI CI4 (/showthread.php?tid=79432)



Error Put method from App in reactNative an RESTAPI CI4 - mailitos - 06-14-2021

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

   

   


RE: Error Put method from App in reactNative an RESTAPI CI4 - rmcdahal - 06-14-2021

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.


RE: Error Put method from App in reactNative an RESTAPI CI4 - paliz - 06-14-2021

See this

https://codeigniter.com/user_guide/incoming/methodspoofing.html

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

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


RE: Error Put method from App in reactNative an RESTAPI CI4 - InsiteFX - 06-15-2021

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.



RE: Error Put method from App in reactNative an RESTAPI CI4 - mailitos - 06-15-2021

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

https://codeigniter.com/user_guide/incoming/methodspoofing.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


RE: Error Put method from App in reactNative an RESTAPI CI4 - paliz - 06-16-2021

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