I am developing a REST api using PHP and Yii2. I have created a custom class for creating (POST) an entity. in that class I have the following code:
if (!$this->AuthenticateRegister($username, $token)) {
throw new ForbiddenHttpException("Invalid token");
}
When I try this locally (WAMP on windows) every thing works fine and I get the proper HTTP status code
But when I upload the code on the host (cpanel) I always get 200 in response
since the HTTP status codes are needed on the client side, how can I resolve this issue?
Related
When fetching custom rest api endpoint from magento 2 for downloading PDF file, request takes around 1 minute and then error in console is shown:
ERR_HTTP2_PROTOCOL_ERROR 200
Failed to fetch
When I test it on my local instance it works fine, but when deployed to staging then it fails.
Does anyone know what that error actually means?
I'm currently trying to wrap my head around Wordpress and its relation to the REST API. All of theses issues are only occurring in the context of plugin development. So far I had setup my endpoint and written my callback which will be executed whenever someone is sending a GET-Request to said endpoint. However, my callback is never called. This is the file which I've written so far.
/*
* Plugin Name: cola-learning
*/
if(!defined('ABSPATH')){
die;
}
if(!function_exists('add_action')){
echo 'You cant access this ressource!';
exit;
}
function PrintRESTResponse()
{
return rest_ensure_response("student");
}
function SetupREST()
{
return register_rest_route("student/v1","/view/",[
'methods' => 'GET',
'callback' => 'PrintRESTResponse'
],false);
}
add_action('rest_api_init','SetupREST');
Perhaps it might also help, if I'll give some background information about my development machine:
- OS: Windows 10
- Server: Apache Web Server (included inside XAMPP)
- Wordpress Version: 5.3.2
- PHP Version: 7.4
- Development IDE: Eclipse 2019-12 CDT ( with PHP Plugin )
From my research, everything should work fine. However, it doesnt :/ Did I miss something crucial?
Update:
WordPress REST API Routing
WordPress is having a default route for all request which are directed to the REST API ( at least if you use XAMPP with the Bitnami WordPress application module). Now, if one wants to send a request to said REST API, the person needs to use an URL with the form of ip:port/wp-json/rest_route. ip ressembles the ip address of the server which is hosting wordpress. port is the port of said server. wp-json, however, is the portion which differs an ordinary request from a request to the REST API. Everything after this portion (rest_route) is the rest route which I've defined in the above source code.
What went wrong?
My request was pointed to the wrong endpoint. Therefore I used the URL 'localhost:wpPort/wordpress/student/v1/view/'. However, the 'wp-json/' portion is missing. Therefore WordPress will search for a page that doesn't exist in the first place. Instead I should have used the URL 'localhost:wpPort/wordpress/wp-json/student/v1/view/'.
After some troubleshooting it turns out the URL being used to test was missing a part of the endpoint path.
Here is the correct path to test the newly registered endpoint.
localhost:80/wordpress/wp-json/student/v1/view/
Here's some more reading on WP Rest API endpoints:
https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/
I'm implementing a payment method in PHP Laravel 5.6, and i'm supposed to receive an online notification through POST to an url i provide. It is getting Error 403, my POSTS from within the APP work completely fine.
As this POST comes from outside with no csrf, i've added my route on VerifyCSRF exceptions. but still it keeps saying 403.
I'm using Laravel 5.6 on AWS Elastic beanstalk on a load balancer, on top of this i use cloudflare.
web.php route
Route::post('/tpv/notificationOK', 'TPVController#order_notificationOK');
VerifyCsrfToken.php
protected $except = [
'tpv/notificationOK',
'https://www.pcmaker.es/tpv/notificationOK'
];
I expect to receive a POST and execute order_notificationOK function on /tpv/notificationOK URL but instead i'm getting "Server returned HTTP response code: 403 for URL: /tpv/notificationOK"
----------EDIT-------------
Just in case it can help someone, Cloudflare was blocking the POST request causing into an error 403, i just had to whitelist the ip where the POST came from and it works fine.
I am trying to dispatch an action with Reactjs and axios to an api created with php.
When using 'get', I do get the php file in plain text, but when calling the file with the 'post' method I get a 404 error.
The php file is in the same node project but in the api folder. I don't know if I need to create an express server parallel to my app.
Also tried to setup a local server with xampp and I get a 401, even adding the header to the php file where you allow access to everyone;
header("Access-Control-Allow-Origin: *");
My code to dispatch the action:
return axios.post('http://localhost:8000/api/auth.php', data).then(res => {
const token = res.data.token;
dispatch(setCurrentUser(jwtDecode(token)));
});
I am new to a lot of these concepts so some help would be great. My possible solution would be continue testing the access to my xampp local server or try with an express server. This last one I am not sure if it can run php scripts.
But what I would like the most is to just call with axios the file in my project, and this is why I need help.
Thanks in advance!
I am using Nusoap library in codeigniter. My code works fine in localhost as well as on server before i make new folder for my testing purpose. But now in testing folder it gives error like this.
I'm receiving this Error:
HTTP Error: Unsupported HTTP response status 404 Not Found
(soapclient->response has contents of the response)
I have searched solution Here and Here but it shows that endpoint is not set for client. On my side, when I print my object it has the endpoint value... What do I do wrong?
I can't connect the URL(http://carvilshoe.cz.cc/index.wsdl.php?wsdl) from my web browser too. I think you have to check your WebService status is online.