Ranjit Pati Ranjit Pati - 5 months ago 72
Android Question

HTTP/1.1 405 Method Not Allowed for WebApi(MVC 5) PUT Method

My android app needs to update some data to server for which I have written some WebApi code for update and sending data from my android app.
Both working fine when I'm testing in local server, but after uploading to global it doesn't work and gives error like:(tested both in android app and fidler)

HTTP/1.1 405 Method Not Allowed
Content-Type: text/html
Server: Microsoft-IIS/8.0

I used simple code both in Android and C#:

Android Code:

HttpClient client = new DefaultHttpClient();
HttpPut post = new HttpPut(PUT_SETTINGS_DATA);
try {
JSONStringer vm = new JSONStringer().object().key("UserId")
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");

StringEntity entity = new StringEntity(vm.toString());
HttpResponse response = client.execute(post);
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String vv = "";
while((vv = br.readLine()) != null){
Log.v("Response Count", vv+" "+UserId);

} catch (JSONException e1) {
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block

WebApi Code:

public int Put(SettingsVM vm)
using (var db = new ApiDBContext())

string sqlQry = "Select COUNT(ID) FROM Settings WHERE UserId= '" + vm.UserId + "'";
var count = db.Database.SqlQuery<Int32>(sqlQry).SingleOrDefault();
if (count != 0)
string sql = "Update Settings Set IsGPSOn={1} where UserId={0}";
count = db.Database.ExecuteSqlCommand(sql, new object[] { vm.UserId, vm.IsGPSOn });
string sql = "INSERT INTO Settings(UserId,IsGPSOn) VALUES({0},{1})";
count = db.Database.ExecuteSqlCommand(sql, new object[] { vm.UserId, vm.IsGPSOn });
return count;



I already check and test all possible solutions to resolve this error.But facing the same issue.



As I can see from your post, you're using IIS/8.0. The error 405: Method not allowed for the PUT, and also DELETE, verb is a well-known issue with this environment.

All evidence seems to centre around interference by an IIS module called WebDAV. You will need to either uninstall it globally or disable it locally for your project. In addition, you may need to edit your applicationhost.config file in order to allow the PUT verb.

If you know you won't need WebDAV, it's probably better to fully disable it or uninstall it from IIS. However, if you don't know if you or someone else sharing your server need it, then it's better to disable the features you don't need locally for your project in order to avoid causing problems for others.

I could either duplicate another SO Q&A here or you could just take a look at the accepted answer to this question and also the non-accepted answer to this question.

People normally frown upon answers that are based on information contained in links but, since they are both in SO, I'm hoping they will stay active as long as your question is active. If you find any of the information useful, please consider upvoting them.

Finally, this (external to SO) link also explains how to globally uninstall the WebDAV feature from the IIS Roles and Features configuration.