本文介绍了得到错误“远程服务器返回错误:(407)需要代理身份验证."在更新共享点列表项时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个窗口应用程序,通过它我可以读取excel文件并批量更新列表项.我正在使用GetAuthenticatedContext.首先,我得到错误远程服务器返回错误:(403)禁止的异常."经过更新 1500项,然后我使用  e.WebRequestExecutor.WebRequest.UserAgent ="Mozilla/5.0(兼容; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"修复了;下面是完整的代码:-

I have a window application through which I am reading excel file and updating list items in bulk. I am using GetAuthenticatedContext. First I got error "The remote server returned an error: (403) Forbidden exception." after updating around 1500 items then I fixed using " e.WebRequestExecutor.WebRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"; below is the full code:-

 公共静态ClientContext GetAuthenticatedContext(ClientContext上下文,字符串targetSiteUrl,int popUpWidth,int popUpHeight)
        {

            Cookies = AuthenticationClaimClientContext.GetAuthenticatedCookies(targetSiteUrl,popUpWidth,popUpHeight);

           如果(cookies == null)返回null;
           试试
            {
                context.ExecutingWebRequest + =委托(对象发送者,WebRequestEventArgs e)
                {
                    e.WebRequestExecutor.WebRequest.UserAgent ="Mozilla/5.0(兼容; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach(cookie中的Cookie cookie)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }

 public static ClientContext GetAuthenticatedContext(ClientContext context, string targetSiteUrl, int popUpWidth, int popUpHeight)
        {

            cookies = AuthenticationClaimClientContext.GetAuthenticatedCookies(targetSiteUrl, popUpWidth, popUpHeight);

            if (cookies == null) return null;
            try
            {
                context.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e)
                {
                    e.WebRequestExecutor.WebRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
                    e.WebRequestExecutor.WebRequest.CookieContainer = new CookieContainer();
                    foreach (Cookie cookie in cookies)
                    {
                        e.WebRequestExecutor.WebRequest.CookieContainer.Add(cookie);
                    }
                };
            }

再次解决此问题后,服务器出现另一个错误"Message ="意外响应.响应的内容类型是\"text/html; charset = UTF-8 \".状态码是"OK".请帮助我解决此问题.

After fixing this again I got another error "Message = "Unexpected response from the server. The content type of the response is \"text/html;charset=UTF-8\". The status code is \"OK\". Please help me to fix this issue.

非常感谢您.

推荐答案

使用SharePoint客户端对象模型时会收到407错误吗?

Did you get 407 error when using SharePoint Client Object Model ?

在这种情况下,请尝试在app.config中将默认代理凭据设置为true:

If that is the case, please try to set default proxy credential to true in app.config:

 <system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
  </system.net>

这里有一个类似的线程供您参考:

Here is a similiar thread for your reference:

https://stackoverflow.com/questions/4151714/how-do-i-pass-my-proxy-credentials-to-a-sharepoint-client-context-object-sh

谢谢

最好的问候


这篇关于得到错误“远程服务器返回错误:(407)需要代理身份验证."在更新共享点列表项时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:26