PDA

View Full Version : Doing Ext.Ajax.request PUT to REST services and getting back a 405 Method Not Allowed



dcarvalho
5 Sep 2012, 12:52 PM
Hi,

I'm doing Ext.Ajax.request PUT to REST services and getting back a 405 (Method Not Allowed)

I can use the Google REST Console Application and do the same request fine, the difference is the Ext.Ajax.request changes the method "PUT" into "OPTIONS" - any ideas?


Header:

Request URL:
http://xxx.xx.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah
Request Method:
OPTIONS
Status Code:
http://www.sencha.com/forum/chrome-devtools://devtools/Images/errorRedDot.png405 Method Not Allowed
Request Headersview source

Accept:
*/*
Accept-Charset:
ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:
gzip,deflate,sdch
Accept-Language:
en-US,en;q=0.8
Access-Control-Request-Headers:
origin, x-requested-with, content-type
Access-Control-Request-Method:
PUT
Connection:
keep-alive
Host:
xxx.xx.58.167
Origin:
http://xxx.xx.60.76
Referer:
http://xxx.xx.60.76/Connect/index.html
User-Agent:
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1

Query String Parametersview URL encoded

session:
blah

Response Headersview source

Cache-Control:
no-cache
Content-Length:
64
Content-Type:
application/json; charset=utf-8
Date:
Wed, 05 Sep 2012 23:37:07 GMT
Expires:
-1
Pragma:
no-cache
Server:
Microsoft-IIS/7.5
X-AspNet-Version:
4.0.30319
X-Powered-By:
ASP.NET

Console log:
OPTIONS http://xxx..xx.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah (http://3.26.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah) 405 (Method Not Allowed) sencha-touch-all.js:41617 (http://3.26.60.76/Connect/sdk/sencha-touch-all.js)
XMLHttpRequest cannot load http://xxx.xx.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah (http://3.26.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah). Origin http://xxx.xx.60.76 (http://3.26.60.76/) is not allowed by Access-Control-Allow-Origin.
server-side failure with status : 0




var jsonObj =
{
"PropertyName": "PCV.Elevation",
"Value": "88",
"setValue": true
};
var newProperties = "http://xxx.xx.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah (http://3.26.58.167/ProficyWebApi/api/Equipment/4ee684ac-2b34-42c1-aef1-49eed1b56cd5/Properties/PCV.Elevation?session=blah)";
Ext.Ajax.request(
{
type: 'json',
method: 'PUT',
url: newProperties,
jsonData: Ext.encode(jsonObj),
Authorization: 'Session test',
scope: this,
success: function(response, opts)
{
var obj = Ext.decode(response.responseText);
if (obj.Success === true)
{
console.log(obj.Location);
//this.GetAuthResult(obj.Location);
}
else
{
Ext.Msg.alert(Utils.Nls.nls("Error"),Utils.Nls.nls(obj.FailureText));
}
},
failure: function(response, opts)
{
console.log('server-side failure with status : ' + response.status);
console.log('response');
console.log(response);
console.log('opts');
console.log(opts);
//Ext.Msg.alert(Utils.Nls.nls("Error"),Utils.Nls.nls("Unable to reach server."));
}
});

Thanks,
- Dan

evant
5 Sep 2012, 12:53 PM
Moving to help. Also, in future please use code tags.

scottmartin
5 Sep 2012, 3:04 PM
If you enter the URL in a browser, what is the response?
Is this a cross domain request? then use: jsonp

Scott.

blaynewatt
6 Sep 2012, 4:04 AM
Sencha always seems to prefix any request to the service with a request for OPTIONS. Is there any way to suppress this? We know PUT is supported, it's our server and our client. On mobile, we want to increase responsiveness and adding a second call to the server is not the way to make a communications package "snappy"... it adds extra bandwidth usage and more turnaround time on the request / response...

-Blayne
General Electric