亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

為什麼 $id 變數(shù)在 WAMP 伺服器上會(huì)自動(dòng)轉(zhuǎn)換為字串,但在 Bluehost 伺服器上卻不會(huì)?
P粉933003350
P粉933003350 2023-09-08 23:26:44
0
1
626

在 PHP 中,$id 變數(shù)應(yīng)該從客戶端接收一個(gè)整數(shù)值。但是,當(dāng)客戶端使用POST請(qǐng)求方法將id值作為整數(shù)傳送到PHP腳本時(shí),當(dāng)腳本上傳到WAMP伺服器時(shí),它會(huì)自動(dòng)轉(zhuǎn)換為PHP中的字串類型。另一方面,當(dāng)腳本上傳到Bluehost伺服器上時(shí),id值仍然是整數(shù),不會(huì)轉(zhuǎn)換為字串,這正是我想要的。

這是一個(gè)簡(jiǎn)單的 PHP 腳本:

<?php

$id = $_POST["id"];

if (is_int($id))
    echo "It is integer"; // It will print this if the PHP script was uploaded to the Bluehost server.
else if (is_string($id))
    echo "It is string"; // It will print this if the PHP script was uploaded to the WAMP server.

從客戶端發(fā)送的 id 值是透過 Android 應(yīng)用程式發(fā)送的,這就是我將 id 值發(fā)送到 PHP 腳本的方式:

RetrofitManager 類別

public class RetrofitManager {

    private static RetrofitManager.Api api;

    public static RetrofitManager.Api getApi() {
        if (api == null)
            api = new Retrofit.Builder()
                .baseUrl("http://192.151.5.721/API/")
                .client(new OkHttpClient.Builder().readTimeout(3, TimeUnit.MINUTES).writeTimeout(3, TimeUnit.MINUTES).connectTimeout(25, TimeUnit.SECONDS).build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .build()
                .create(Api.class);

        return api;
    }

    public interface Api {

        @FormUrlEncoded
        @POST("Countries/Get.php")
        Single<CountryModelResponse> getCountries(@Field("id") int countryId);

    }

}

CountriesRepository 類別

public class CountriesRepository {

    public LiveData<Object> getCountries(Context context) {
        MutableLiveData<Object> mutableLiveData = new MutableLiveData<>();
        PublishSubject<String> retrySubject = PublishSubject.create();

        RetrofitManager.getApi().getCountries(Navigation.findNavController(MainActivity.activityMainBinding.activityMainFragmentContainerViewContainer).getPreviousBackStackEntry() == null ? SharedPreferencesManager.getIntegerValue(context, SharedPreferencesManager.Keys.COUNTRY_ID.name()) : -1)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(mutableLiveData::setValue)
            .doOnError(throwable -> {
                LinkedHashSet<Object> linkedHashSet = new LinkedHashSet<>();
                linkedHashSet.add(!Utils.isInternetConnected(context) ? 100 : throwable instanceof SocketTimeoutException ? 200 : 300);
                linkedHashSet.add(retrySubject);
                mutableLiveData.setValue(linkedHashSet);
            })
            .retryWhen(throwableFlowable -> throwableFlowable.flatMap(throwable -> retrySubject.toFlowable(BackpressureStrategy.DROP).take(1), (throwable, s) -> s))
            .subscribe(countryModelResponse -> {
                if (countryModelResponse.getRequestStatus() == 100)
                    mutableLiveData.setValue(countryModelResponse);
                else {
                    LinkedHashSet<Object> linkedHashSet = new LinkedHashSet<>();
                    linkedHashSet.add(300);
                    linkedHashSet.add(retrySubject);
                    mutableLiveData.setValue(linkedHashSet);
                }
            });

        return mutableLiveData;
    }

}

我不確定為什麼兩臺(tái)伺服器之間會(huì)出現(xiàn)這種行為差異。

我正在使用最新版本的 PHP 和 WAMP 伺服器。

P粉933003350
P粉933003350

全部回覆(1)
P粉178894235

所有透過 HTTP 的請(qǐng)求都會(huì)以字串傳送。我們必須根據(jù)我們的需要來鑄造它。就你而言,行為很奇怪。嘗試檢查兩端的PHP版本是否相同。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板