[英]Status code 403 forbidden unable to encode multipartform data using postAsync method on wsdl webservice?
我是wsdl
webservice 的新手我正在使用 abbyy flexicapture webservice 來上傳 fexicapture 中的文件並獲取 xml 中的數據。 現在主要問題出現了我將在我的代碼處於調試模式時獲取數據,即在本地機器上,但是當我將代碼發布到遠程服務器時,我將在 postAsync 方法中編碼數據時收到 403 錯誤。 Abbyy flexicapture 分享了一個演示項目https://help.abbyy.com/en-us/flexicapture/12/developer/unattendedexample通過使用該代碼我創建了一個 MVC 應用程序,在該應用程序中我成功地從使用 window 的服務器上的 flexicapture 獲取數據在我的本地機器上進行身份驗證。
我正在與您分享我的錯誤,請找到
Error :-EXCEPTION OCCURRED:System.Net.Http.HttpRequestException Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at WebServices.Controllers.HomeController.<FileRequest>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at WebServices.Controllers.HomeController.<UploadFile>d__17.MoveNext() System.Net.Http.HttpResponseMessage EnsureSuccessStatusCode()
Flexicapture 和 Webservice 位於遠程服務器上的同一個 IIS 上。
在此先感謝請幫助我。
private static async Task<HttpResponseMessage> FileRequest(FlexicaptureWebservice.FlexiCaptureWebServiceSoapClient service, string action,int objectType, int sessionId, int projectId, int batchId, int parentId, int objectId, int version, string streamName)
{
var creds = CredentialCache.DefaultNetworkCredentials;
if (!string.IsNullOrEmpty(service.ClientCredentials.UserName.UserName))
creds = new NetworkCredential(service.ClientCredentials.UserName.UserName, service.ClientCredentials.UserName.Password);
using (var handler = new HttpClientHandler { Credentials = creds })
{
using (var client = new HttpClient(handler))
{
var uri = service.Endpoint.Address.Uri;
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"Action", action},
{"objectType", objectType.ToString()},
{"sessionId", sessionId.ToString()},
{"projectId", projectId.ToString()},
{"batchId", batchId.ToString()},
{"parentId", parentId.ToString()},
{"objectId", objectId.ToString()},
{"version", version.ToString()},
{"streamName", streamName},
});
var response = await client.PostAsync(uri.OriginalString.Replace("/API/v1/Soap","/FileService/v1").Trim(), content).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
client.Dispose();
return response;
}
}
}
由於服務器 IIS 上的某些身份驗證問題,我導致了此錯誤。 所以在我的本地構建它工作正常但是當我在 IIS 上發布東西時導致錯誤
我將我的代碼發布到遠程服務器,在 postAsync 方法中編碼數據時會出現 403 錯誤。
因此,為了消除錯誤,我轉到-> IIS 應用程序池-> 高級設置-> 身份-> 添加自定義帳戶,我將服務器憑據放在那里。
現在我可以在 flexicature 上發送文件了。 我希望這個小小的改變能幫助一些開發者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.