Unexpected Response Code 403 Hatası
-
Android volley library kullanıyorum.
Sunucuda wamp kurulu, local den bağlantı kurmaya çalışıyorum.
Slim Framework kullanıyorum orada da. Onun içeriği şöyle :
<?php //including the required files require '../libs/Slim/Slim.php'; require '../classes/C_LoginSignup.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); /* * * URL: http://easypath.com.tr/api/v1/register * Parameters: name, surname, email, password * Authorization: Put API Key in Request Header * Method: POST * */ $app->post('/register', function() use ($app) { verifyRequiredParams(array('name', 'surname', 'email', 'password')); $name = $app->request->post('name'); $surname = $app->request->post('surname'); $email = $app->request->post('email'); $password = $app->request->post('password'); $objLogReg = new LoginSignup; $result = $objLogReg->storeUser($name, $surname, $email, $password); if (!$result) { // user failed to store $response["error"] = TRUE; $response["error_msg"] = "Bilinmeyen bir hata oluştu!"; } else { $response["error"] = FALSE; $response["uid"] = $result["unique_id"]; $response["user"]["name"] = $result["name"]; $response["user"]["surname"] = $result["surnname"]; $response["user"]["email"] = $result["email"]; $response["user"]["created_at"] = $result["created_at"]; $response["user"]["updated_at"] = $result["updated_at"]; $response["user"]["api_key"] = $result["api_key"]; } echoResponse(200, $response); }); /* * * URL: http://easypath.com.tr/api/v1/userlogin * Parameters: email, password * Authorization: Put API Key in Request Header * Method: POST * */ $app->post('/userlogin', function() use ($app) { verifyRequiredParams(array('email', 'password')); $email = $app->request->post('email'); $password = $app->request->post('password'); $objUserRegLog = new UserRegistrationLogin; $result = $objUserRegLog->getUserByEmailAndPassword($email, $password); if (!$result) { $response["error"] = true; $response["message"] = _("E-Posta ya da şifreniz hatalı!"); } else { $response["error"] = false; $response["id"] = $result["id"]; $response["email"] = $result["email"]; $response["api_key"] = $result["api_key"]; } echoResponse(200, $response); }); //Method to display response function echoResponse($status_code, $response) { //Getting app instance $app = \Slim\Slim::getInstance(); //Setting Http response code $app->status($status_code); //setting response content type to json $app->contentType('application/json'); //displaying the response in json format echo json_encode($response); } function verifyRequiredParams($required_fields) { $error = false; $error_fields = ""; $request_params = $_REQUEST; if ($_SERVER['REQUEST_METHOD'] == 'PUT') { $app = \Slim\Slim::getInstance(); parse_str($app->request()->getBody(), $request_params); } foreach ($required_fields as $field) { if (!isset($request_params[$field]) || strlen(trim($request_params[$field])) <= 0) { $error = true; $error_fields .= $field . ', '; } } if ($error) { $response = array(); $app = \Slim\Slim::getInstance(); $response["error"] = true; $response["message"] = 'Required field(s) ' . substr($error_fields, 0, -2) . ' is missing or empty'; echoResponse(200, $response); $app->stop(); } } function authenticatePathologist(\Slim\Route $route) { $headers = apache_request_headers(); $response = array(); $app = \Slim\Slim::getInstance(); if (isset($headers['Authorization'])) { $objUserRegLog = new UserRegistrationLogin; $api_key = $headers['Authorization']; if (!$objUserRegLog->isValidPathologist($api_key)) { $response["error"] = true; $response["message"] = "Access Denied. Invalid Api key"; echoResponse(401, $response); $app->stop(); } } else { $response["error"] = true; $response["message"] = "Api key is misssing"; echoResponse(400, $response); $app->stop(); } } $app->run(); ?>Android' den verdiğim link : http://192.168.1.4/api/v1/register
Yukarıdaki kendi ip' m. Index.php de /api/v1/ folder' ının altında.
Bu da .htaccess :
RewriteEngine On RewriteBase /api/v1/ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]O register' ı get yapıp içine de echo "özgün"; diye bastırıp normal bilgisayarımdan : http://localhost/api/v1/register diye çağırınca ekrana basıyor.
Ama böyle post iken 404 not found veriyor.
Apache httpd.conf içeriği şöyle :
<Directory /> AllowOverride none Require all granted </Directory>Ayrıca;
DocumentRoot "c:/wamp/www" <Directory "c:/wamp/www/"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options +Indexes +FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride all # # Controls who can get stuff from this server. # # onlineoffline tag - don't remove Require local </Directory>
Buradaki Require local' i all granted yapıp denedim olmadı.
Mod rewrite rule apache de açık.
Sorun nerede onu da bulamadım açıkcası.
Windows firewall' ı tamamen kapatıp denedim, olmadı.
Bu da android tarafı :
/** * Function to store user in MySQL database will post params(tag, name, * email, password) to register url * */ private void registerUser(final String name, final String surname, final String email, final String password) { // Tag used to cancel the request String tag_string_req = "req_register"; pDialog.setMessage("Kayıt yapılıyor ..."); showDialog(); StringRequest strReq = new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d(TAG, "Register Response: " + response.toString()); hideDialog(); try { JSONObject jObj = new JSONObject(response); boolean error = jObj.getBoolean("error"); if (!error) { // User successfully stored in MySQL // Now store the user in sqlite String uid = jObj.getString("uid"); JSONObject user = jObj.getJSONObject("user"); String name = user.getString("name"); String email = user.getString("email"); String created_at = user .getString("created_at"); // Inserting row in users table db.addUser(name, email, uid, created_at); Toast.makeText(getApplicationContext(), "Kullanıcı kaydı başarıyla oluşturuldu. Giriş yapabilirsiniz!", Toast.LENGTH_LONG).show(); // Launch login activity Intent intent = new Intent( SignupActivity.this, LoginActivity.class); startActivity(intent); finish(); } else { // Error occurred in registration. Get the error // message String errorMsg = jObj.getString("error_msg"); Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, "Registration Error: " + error.getMessage()); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show(); hideDialog(); } }) { @Override protected Map<String, String> getParams() { // Posting params to register url Map<String, String> params = new HashMap<String, String>(); params.put("name", name); params.put("surname", surname); params.put("email", email); params.put("password", password); return params; } }; // Adding request to request queue AppController.getInstance().addToRequestQueue(strReq, tag_string_req); } private void showDialog() { if (!pDialog.isShowing()) pDialog.show(); } private void hideDialog() { if (pDialog.isShowing()) pDialog.dismiss(); }Logcat çıktısı da şu şekilde :
05-21 22:52:26.001 16945-20085/com.ozgun.onlineis E/Volley: [3281] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168.1.4/api/v1/register 05-21 22:52:26.011 16945-16998/com.ozgun.onlineis D/mali_winsys: new_window_surface returns 0x3000, [1592x720]-format:1 05-21 22:52:26.011 16945-16945/com.ozgun.onlineis W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 05-21 22:52:26.021 16945-16945/com.ozgun.onlineis E/SignupActivity: Registration Error: null
-
-
HTML tabanlı bir post testi yaz bakalım
-
@moi zaten all granted yapıp denedim hocam, apache' nin yeni versiyonu var.
@PcK0 hocam bundan önceki proje çalışıyordu web de, android ile erişim izni vermiyor sanırım.
Ama denilen şeyleri de yapıp servisleri hep yeniden başlattım ama yine de 403 veriyor.
