我可以使用这段代码将我的数据发布到 php 文件
Strint senddata = "apple";
Call<DataResponse> call_datas = apiService.getallData(senddata);
call_datas.enqueue(new Callback<DataResponse>() {
@Override
public void onResponse(Call<DataResponse>call, Response<DataResponse> response) {
try{
List<mDatas> mlist = response.body().getResults();
all_recycler.setAdapter(new TestAdapter(mlist, mContext));
}catch (Exception e){ }
}
@Override
public void onFailure(Call<DataResponse>call, Throwable t) {
}
});
接口(interface)接口(interface).java
public interface ApiInterface {
@GET("/test.php")
Call<DataResponse> getallData(@Query("key") String key);
}
但我想将数组列表发送到我的 php 文件。 如何通过改造将字符串数组发送到 php 文件? 示例字符串数组:
String[] senddata= {"apple","banana","peach"}
最佳答案
您只需更改 ApiInterface.java 文件即可。
public interface ApiInterface {
@FormUrlEncoded
@GET("/test.php")
Call<DataResponse> getallData(@Field("key") String[] key);
}
希望对您有所帮助。
关于android - 将 post 数组改造为 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53567404/