Problem description
When using the HTTP verb 'DELETE', the body does not seem to be sent out, when passing it to the send() method.
Steps to reproduce
var payload = {
"first": {
"id" : "11"
},
"second" : "TEST"
};
var xhr = Titanium.Network.createHTTPClient({
onload: function (e) {
alert(this.responseText);
}
});
xhr.open('DELETE', 'SOMESERVER');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(payload));
Running the code, on the server side there is no data received; using PHP, I both verified $_POST and json_decode(file_get_contents('php://input')) and they are empty.
Changing the method to POST or PUT will show the data on the server.
I'm curious if there's an update for this issue? It's a tiny change to the code. It's easy to make the change in the code for iOS and re-build but the Android source code is not exposed so we are a bit stuck here.
This apparently is not native behavior on Android, and is generally not supported by other platforms (iOS appears to be an exception). As iOS is the outlier, we won't/can't bring all the platforms into line. I would suggest passing needed data along the URL.
Ingo, there is code in both the Android and iOS Titanium SDKs to explicitly change DELETE requests to POST requests if you try to pass a request body with a DELETE. Titanium should not be making this decision, it should be left up to the user whether they want to make a DELETE request with a body. It doesn't seem like it relates to what the native behavior is, since Titanium is getting involved before it ever reaches the OS.
We are addressing the iOS issue. Do you have a link for the Android location you are referencing?
Line 1107 of the HTTPClient implementation. A variable is set called isPostOrPut and later on line 1130 it will only send a request body if the method is a POST or PUT request. DELETE requests fall through. https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/network/src/java/ti/modules/titanium/network/TiHTTPClient.java
As noted, it appears that it would be relatively trivial to change the logic around: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/network/src/java/ti/modules/titanium/network/TiHTTPClient.java#L1130 However, if we did so, would it work? http://stackoverflow.com/questions/10338615/sending-http-delete-request-in-android Suggests that it might not even send the data.
Yeah, digging further in there seems to be some debate as to whether DELETEs should be able to have a body, even though the RFC seems to indicate they can. I guess it would need to be tested. I know that when I made the modification to the iOS code, it started sending the request body without issue. I have not tested with Android as I'm not as familiar with recompiling the SDK.
Closing ticket as "Won't Fix". There has been no update for a while. If there is any problem, please open a new ticket.
Hi guys, this is not fixed in 6.3.0, http request doesn't send body for DELETE type. Can you please make it work as iOS does(iOS doesn't have a problem). Thanks