2013-07-30 65 views
0

我正在開發SharePoint託管應用程序。在這個應用程序中,我想將需要用戶名和密碼的跨域第三方Rest服務「Post」數據(多個文件流作爲多部分表單數據)傳遞給POST請求。我發現很多樣本可以通過「GET」操作訪問跨域REST服務,沒有用戶名和密碼。這些示例工作正常與GET操作,沒有用戶名和密碼,但不支持我的情況下,我想發送用戶名和密碼和多部分表單數據。SharePoint 2013託管APP。跨域問題

我已經看到了提琴手會議,我雖然發送的授權標題值是用戶名和密碼的散列值組合。但是這種努力無法成功地將用戶名和密碼傳遞給其他服務。另外我需要找到一種方法將多部分表單數據發送到REST服務。

下面是在MSDN論壇上提出的問題, http://social.technet.microsoft.com/Forums/sharepoint/en-US/d4302523-82cc-4732-a89b-05eb0bbafadf/sharepoint-2013-hosted-app-cross-domain-issue

回答

0

我不知道,如果你的問題已經得到解決還沒有,但下面是添加,刪除和更新項目中爲SharePoint列表的例子託管應用程序進行跨域調用一個分享點列表。

function addItem() { 
var executor = new SP.RequestExecutor(appweburl); 

var dataTobeSent = { 
    __metadata: { "type": "SP.Data.TestListforAppListItem" }, 
    Title: $("#col1").val(), 
    testCol1: $("#col2").val(), 
    test_x0020_col_x0020_2: $("#col3").val() 
}; 

var sendData = JSON.stringify(dataTobeSent); 

executor.executeAsync(
    { 
     url: 
      appweburl + 
      "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/[email protected]='" + 
      hostweburl + "'", 
     contentType: "application/json;odata=verbose", 
     method: "POST", 
     body: sendData, 
     headers: { 
      "Accept": "application/json;odata=verbose", 
      "content-type": "application/json;odata=verbose", 
      "X-RequestDigest": $("#__REQUESTDIGEST").val() 
     }, 
     success: getAllListItems, 
     error: errorHandler 
    } 
); 
} 

function deleteItem(id) { 
var executor = new SP.RequestExecutor(appweburl); 
executor.executeAsync(
    { 
     url: 
      appweburl + 
      "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/items(" + id + ")[email protected]='" + 
      hostweburl + "'", 
     contentType: "application/json;odata=verbose", 
     method: "POST", 
     headers: { 
      "Accept": "application/json;odata=verbose", 
      "content-type": "application/json;odata=verbose", 
      "X-Http-Method": "DELETE", 
      "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
      "If-Match": "*" 
     }, 
     success: getAllListItems, 
     error: errorHandler 
    } 
); 
} 

function updateItem(id) { 
var executor = new SP.RequestExecutor(appweburl); 

var dataTobeSent = { 
    __metadata: { "type": "SP.Data.TestListforAppListItem" }, 
    Title: $("#col1").val(), 
    testCol1: $("#col2").val(), 
    test_x0020_col_x0020_2: $("#col3").val() 
}; 

var sendData = JSON.stringify(dataTobeSent); 

executor.executeAsync(
    { 
     url: 
      appweburl + 
      "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('testListforApp')/items(" + id + ")[email protected]='" + 
      hostweburl + "'", 
     contentType: "application/json;odata=verbose", 
     method: "POST", 
     body: sendData, 
     headers: { 
      "Accept": "application/json;odata=verbose", 
      "content-type": "application/json;odata=verbose", 
      "X-HTTP-Method": "MERGE", 
      "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
      "If-Match": "*" 
     }, 
     success: getAllListItems, 
     error: errorHandler 
    } 
); 
} 

希望這會有所幫助。