I am trying to send a PUT request method from my Android application to a PHP endpoint, but at my endpoint, the PUT request is not recognized as a PUT request, so I am returning the request method incorrectly! . from my endpoint.
Android interface and query execution
Interface to activate
@PUT("device/activate.php")
Call<DeviceRegistry> registryDevice();
Query execution
DeviceRegistryAPI registryAPI =
RetrofitController.getRetrofit().create(DeviceRegistryAPI.class);
Call<DeviceRegistry> registryCallback = registryAPI.registryDevice();
response = registryCallback.execute();
With this, I expect an answer, but I get an endpoint error message.
My PHP endpoint
if($_SERVER['REQUEST_METHOD'] == "PUT"){
} else {
$data = array("result" => 0, "message" => "Request method is wrong!");
}
I don’t know why it $_SERVER['REQUEST_METHOD'] == "PUT"is false, but I wonder if something is missing on Retrofit 2.
Additional Information.
I am using Retrofit2.
Update 1: sending json to body
I am trying to send json using body.
This is my json:
{
"number": 1,
"infoList": [
{
"id": 1,
"info": "something"
},
{
"id": 2,
"info": "something"
}
]
}
There are my classes:
class DataInfo{
public int number;
public List<Info> infoList;
public DataInfo(int number, List<Info> list){
this.number = number;
this.infoList = list;
}
}
class Info{
public int id;
public String info;
}
I changed the PUT interface to this:
@PUT("device/activate.php")
Call<DeviceRegistry> registryDevice(@Body DataInfo info);
.
2:
REstfull:
Accept: application/json
Content-Type: application/x-www-form-urlencoded
? , ?
3: .
. PUT/POST. , , .
, (PUT/POST), php GET? ( POST, )
Call<UpdateResponse> requestCall = client.updateMedia(downloadItemList);
Log.i("CCC", requestCall .request().toString());
- POST:
Request{method=POST, url=http://myserver/api/v1/media/updateMedia.php, tag=null}
POST ( , PUT) , GET. !!! , .
4: godaddy.
php- godaddy. ? , , godaddy. , , , Godaddy ?