0

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' と一致しません? ありがとう

4

1 に答える 1

2

OK、これらの行を追加/変更すると機能することがわかりました。

postURL.requestHeaders.push( new URLRequestHeader("ContentType","application/json;odata=verbose"));
postURL.requestHeaders.push( new URLRequestHeader("X-RequestDigest",FormDigestValue ));
postURL.requestHeaders.push( new URLRequestHeader("If-Match","*"));
postURL.requestHeaders.push( new URLRequestHeader("X-Http-Method","POST"));
postURL.contentType="application/json;odata=verbose";
于 2013-01-15T08:03:47.143 に答える