После переноса сайта на другой сервер мой php api перестал работать. Теперь мой API считает, что тело сообщения, отправленное через Retorift, пусто (хотя это не так), когда при отправке, например, через reqbin, все работает
Журналы
D/OkHttp: --> POST https://site-url
Content-Type: application/json; charset=UTF-8
Content-Length: 55
D/OkHttp: {"login":"*****","password":"******"}
--> END POST (55-byte body)
D/OkHttp: <-- 200 OK https://site-url (492ms)
Server: nginx
Date: Sat, 12 Oct 2019 19:52:40 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.3.10
Vary: Accept-Encoding
MS-Author-Via: DAV
X-Powered-By: PleskLin
D/OkHttp: login/password is null
D/OkHttp: <-- END HTTP (22-byte body)
PHP API
// Converts into a PHP object
$data = json_decode(file_get_contents('php://input'), true);
$login = $data['login'];
$password = $data['password'];
if (isset($_GET['type']) && $_GET['type'] != NULL) {
switch ($_GET['type']) {
case "auth":
if($login != NULL && $password != NULL) {
emailOrUsername($login, $password, $db);
} else echo 'login/password is null';
break;
case "token":
if($login != NULL && $password != NULL) {
compareMailToken($login, $password, $db);
} else echo 'login/password is null';
break;
}
}
var_dump (file_get_contents ('php: // input')) возвращает строку (0) ""
API Mobile Retrofit
interface AuthApi {
@POST("auth.php?type=auth")
fun authWithPass(@Body loginBody: LoginBody): Call<AuthResponse>
}
class AuthResponse(
@SerializedName("type")
val type: AuthResponseType,
@SerializedName("user")
val user: User?,
@SerializedName("message")
val message: String)
LoginBody
data class LoginBody(val login: String, val password: String)
AuthModel
override fun authWithPass(onFinishedListener: AuthContract.Model.OnFinishedListener, email: String, password: String) {
val authApi = RetrofitApi.getInstance().create(AuthApi::class.java)
val loginBody = LoginBody(email, password)
val authQuery = authApi.authWithPass(loginBody)
authQuery.enqueue(object : Callback<AuthResponse>{
override fun onResponse(call: Call<AuthResponse>, response: Response<AuthResponse>) {
response.body()?.let { body ->
onFinishedListener.onFinished(body.type, body.user, body.message)
} ?: onFinishedListener.onFinished()
}
override fun onFailure(call: Call<AuthResponse>, t: Throwable) {
onFinishedListener.onFailure(t)
}
})
}
RetrofitObject
object RetrofitApi {
private var BASE_URL = "https://site-url/"
private var retrofit: Retrofit? = null
fun getInstance(): Retrofit {
if (retrofit == null) {
val gson = GsonBuilder()
.setLenient()
.create()
val logging = HttpLoggingInterceptor()
// set your desired log level
logging.level = HttpLoggingInterceptor.Level.BODY
val httpClient = OkHttpClient.Builder().apply {
connectTimeout(30, TimeUnit.SECONDS)
readTimeout(30, TimeUnit.SECONDS)
addInterceptor(logging)
}
retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(httpClient.build())
.build()
}
return retrofit!!
}
}