在将站点移动到另一台服务器后,我的php停止工作。现在,我的api认为,通过Retorift发送的post主体是空的(尽管这不是),如果通过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)// 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
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!!
}
}发布于 2019-10-27 07:19:16
这是由重定向(从www.url重定向到url等)造成的,这就是为什么我的php://input是空的。
https://stackoverflow.com/questions/58358138
复制相似问题