public static FileInformation OpenBinaryDirect(ClientContext context, string serverRelativeUrl)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.HasPendingRequest)
            {
                throw new ClientRequestException(Resources.GetString("NoDirectHttpRequest"));
            }
            string             requestUrl         = File.MakeFullUrl(context, serverRelativeUrl);
            WebRequestExecutor webRequestExecutor = context.WebRequestExecutorFactory.CreateWebRequestExecutor(context, requestUrl);

            webRequestExecutor.RequestHeaders[HttpRequestHeader.Translate] = "f";
            context.FireExecutingWebRequestEventInternal(new WebRequestEventArgs(webRequestExecutor));
            webRequestExecutor.GetRequestStream().Write(new byte[0], 0, 0);
            webRequestExecutor.RequestMethod = "GET";
            webRequestExecutor.Execute();
            if (webRequestExecutor.StatusCode != HttpStatusCode.OK)
            {
                throw new ClientRequestException(Resources.GetString("RequestUnexpectedResponseWithContentTypeAndStatus", new object[]
                {
                    webRequestExecutor.ResponseContentType,
                    webRequestExecutor.StatusCode
                }));
            }
            string etag           = webRequestExecutor.ResponseHeaders["ETag"];
            Stream responseStream = webRequestExecutor.GetResponseStream();

            return(new FileInformation(responseStream, etag));
        }
        private string ReadSoapResponse(WebRequestExecutor requestExecutor)
        {
            string soapResponse = "";

            using (StreamReader sr = new StreamReader(requestExecutor.GetResponseStream()))
            {
                soapResponse = sr.ReadToEnd();
            }
            return(ReadSoapResponse(soapResponse));
        }
Beispiel #3
0
        private FormDigestInfo GetFormDigestInfoPrivate()
        {
            string             sitesAsmxUrl       = this.GetSitesAsmxUrl();
            WebRequestExecutor webRequestExecutor = base.WebRequestExecutorFactory.CreateWebRequestExecutor(this, sitesAsmxUrl);

            this.FireExecutingWebRequestEventInternal(new WebRequestEventArgs(webRequestExecutor));
            webRequestExecutor.RequestContentType           = "text/xml";
            webRequestExecutor.RequestHeaders["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/GetUpdatedFormDigestInformation";
            if (base.AuthenticationMode == ClientAuthenticationMode.Default)
            {
                webRequestExecutor.RequestHeaders["X-RequestForceAuthentication"] = "true";
            }
            this.BuildGetUpdatedFormDigestInfoRequestBody(webRequestExecutor.GetRequestStream());
            //Edited for .NET Core - Calling dispose does not work because now they are Async methods
            //webRequestExecutor.GetRequestStream().Close();
            //webRequestExecutor.GetRequestStream().Dispose();// Close();
            try
            {
                webRequestExecutor.Execute();
            }
            catch (WebException webEx)
            {
                string text = this.ExtractSoapError(webEx);
                if (string.IsNullOrEmpty(text))
                {
                    throw;
                }
                throw new ClientRequestException(Resources.GetString("CannotContactSiteWithDetails", new object[]
                {
                    base.Url,
                    text
                }));
            }
            if (webRequestExecutor.StatusCode != HttpStatusCode.OK || webRequestExecutor.ResponseContentType.IndexOf("text/xml", StringComparison.OrdinalIgnoreCase) < 0)
            {
                throw new ClientRequestException(Resources.GetString("CannotContactSite", new object[]
                {
                    base.Url
                }));
            }
            FormDigestInfo formDigestInfo = this.ParseFormDigest(webRequestExecutor.GetResponseStream());

            if (formDigestInfo == null)
            {
                throw new ClientRequestException(Resources.GetString("CannotContactSite", new object[]
                {
                    base.Url
                }));
            }
            return(formDigestInfo);
        }