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
Allow: GET, HEAD, OPTIONS, TRACE
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")
.value(UserId).key("IsGPSOn").value(String.valueOf(isServiceOn)).endObject();
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
StringEntity entity = new StringEntity(vm.toString());
post.setEntity(entity);
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) {
e1.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebApi Code:
[HttpPut]
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 });
db.SaveChanges();
}
else
{
string sql = "INSERT INTO Settings(UserId,IsGPSOn) VALUES({0},{1})";
count = db.Database.ExecuteSqlCommand(sql, new object[] { vm.UserId, vm.IsGPSOn });
db.SaveChanges();
}
return count;
}
}
I already check and test all possible solutions to resolve this error.But facing the same issue.
Thanks