我正在尝试执行 POST 以在 AIR 客户端的 Sharepoint 2013 列表中插入值。GET 工作并且身份验证正常。
这是我的 as3 代码:
URLRequestDefaults.authenticate = true;
URLRequestDefaults.setLoginCredentialsForHost("srv", "usr", "pwd");
var postURL:URLRequest= new URLRequest("http://srv/site/_api/web/lists/getByTitle('list')/items");
postURL.authenticate = true;
postURL.method = URLRequestMethod.POST;
postURL.requestHeaders.push( new URLRequestHeader("ACCEPT","application/json;odata=verbose"));
postURL.requestHeaders.push( new URLRequestHeader("ContentType","application/json"));
postURL.data = JSON.stringify({ '_metadata': { 'type': 'SP.listnameListItem' }, 'Title': 'desc' });
postLoader = new URLLoader(postURL);
postLoader.dataFormat = URLLoaderDataFormat.TEXT;
postLoader.addEventListener(flash.events.Event.COMPLETE, postDone);
postLoader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError );
postLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleHttpStatus );
postLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityError );
postLoader.load(postURL);
当我运行它时,它会转到 handleIOError 方法:
private function handleIOError ( event:IOErrorEvent ):void
{
trace ( "Load failed: IO error: " + event.text );
trace ( "data IO error: " + event.currentTarget.data.toString() );
}
我收到此错误:Microsoft.Data.OData.ODataContentTypeException 找不到与响应的内容类型匹配的受支持的 MIME 类型。支持的类型 'application/atom+xml;type=feed, application/atom+xml, application/json;odata=verbose' 不匹配内容类型 'text/xml;charset=utf-8' 任何想法? 谢谢