当前位置: 首页>>代码示例>>C#>>正文


C# StringContent类代码示例

本文整理汇总了C#中StringContent的典型用法代码示例。如果您正苦于以下问题:C# StringContent类的具体用法?C# StringContent怎么用?C# StringContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringContent类属于命名空间,在下文中一共展示了StringContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TelemetryIngest

        public async Task<bool> TelemetryIngest(Telemetry telemetry)
        {

            string serviceBusNamespace = "iotmc-ns";
            string serviceBusUri = string.Format("{0}.servicebus.windows.net", serviceBusNamespace);
            string eventHubName = "IoTMC";
            string eventHubSASKeyName = "Device01";
            string eventHubSASKey = "<< Your SAS Key here >>";

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(String.Format("https://{0}", serviceBusUri));
                httpClient.DefaultRequestHeaders.Accept.Clear();

                string sBToken = CreateServiceBusSASToken(eventHubSASKeyName, eventHubSASKey, serviceBusUri);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("SharedAccessSignature", sBToken);
                HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(telemetry), Encoding.UTF8);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
              
                string ingestPath = String.Format("/{0}/publishers/device01/messages", eventHubName);
                var response = await httpClient.PostAsync(ingestPath, httpContent);
                if (response.IsSuccessStatusCode)
                {
                    return true;
                }

                return false;
            }
        }
开发者ID:HydAu,项目名称:IoTMasterClass,代码行数:29,代码来源:EventHubIngest.cs

示例2: Ctor_EmptyString_Accept

 public async Task Ctor_EmptyString_Accept()
 {
     // Consider empty strings like null strings (null and empty strings should be treated equally).
     var content = new StringContent(string.Empty);
     Stream result = await content.ReadAsStreamAsync();
     Assert.Equal(0, result.Length);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:StringContentTest.cs

示例3: ReadDeeplyNestedObjectThrows

        public void ReadDeeplyNestedObjectThrows()
        {
            FormUrlEncodedMediaTypeFormatter formatter = new FormUrlEncodedMediaTypeFormatter() { MaxDepth = 100 };

            StringContent content = new StringContent(GetDeeplyNestedObject(125));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            Assert.ThrowsArgument(
                () => formatter.ReadFromStreamAsync(typeof(JToken), content.ReadAsStreamAsync().Result, content.Headers, null).Result,
                null);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:11,代码来源:FormUrlEncodedMediaTypeFormatterTests.cs

示例4: PostCallAsync

        public static async Task<string> PostCallAsync(string url, string parameters)
        {
            var content = new StringContent(parameters);
            string output = string.Empty;
            using (var client = new HttpClient())
            {   
                HttpResponseMessage response = await client.PostAsync(url, content);
                output = await response.Content.ReadAsStringAsync();
            }

            return output;
        }
开发者ID:SaintCat,项目名称:VkBot,代码行数:12,代码来源:WebCall.cs

示例5: GivenSomeContentWithNoBadPhrases_PhrasesThatExist_ReturnsANullList

            public void GivenSomeContentWithNoBadPhrases_PhrasesThatExist_ReturnsANullList()
            {
                // Arrange.
                const string content =
                    "foo  1 12l3j1kl;j434;5 3klkrj 987*&^897^DF hsfd l;ajf;o2u3r8fjdasf jdsajf ;aljsfj asf jas;df 8asuf 80sdf 9d (& 8H ";

                var stringContent = new StringContent(PhraseList);

                // Act.
                var results = stringContent.PhrasesThatExist(content);

                // Assert.
                Assert.Null(results);
            }
开发者ID:PureKrome,项目名称:WorldDomination.Text,代码行数:14,代码来源:StringContentFacts.cs

示例6: PapRequestMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="PapRequestMessage"/>
        /// class with both control and content parts.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="content">The content.</param>
        public PapRequestMessage(PushMessageControl control, StringContent content)
        {
            _control = control;
            _content = content;

            BoundaryGenerator bg = new BoundaryGenerator();

            Boundary = bg.MakeBoundary();

            if (content != null && control != null)
            {
                content.PushId = control.PushId;
            }
        }
开发者ID:ngoossens,项目名称:PushSharp,代码行数:20,代码来源:PapRequestMessage.cs

示例7: Dispose_DisposesInnerContent

        public void Dispose_DisposesInnerContent()
        {
            // Arrange
            StringContent innerContent = new StringContent("HelloWorld!");
            HttpRequestMessage request = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();
            ProgressContent progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Act
            progressContent.Dispose();

            // Assert
            Assert.ThrowsObjectDisposed(() => innerContent.LoadIntoBufferAsync(), typeof(StringContent).FullName);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:ProgressContentTest.cs

示例8: GetDataUsingDataContract

 public async Task<CompositeType> GetDataUsingDataContract(CompositeType composite)
 {
     var soapString = this.CreateGetDataUsingDataContractRequest(composite);
     using (var client = new HttpClient())
     {
         client.DefaultRequestHeaders.Add("SOAPAction", "http://tempuri.org/IService1/GetDataUsingDataContract");
         var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
         using (var response = await client.PostAsync(this.uri, content))
         {
             string soapResponse = await response.Content.ReadAsStringAsync();
             CompositeType result = this.ParseGetDataUsingDataContractResponse(soapResponse);
             return result;
         }
     }
 }
开发者ID:ylemsoul,项目名称:XamarinWithWCF,代码行数:15,代码来源:Service1Client.cs

示例9: Constructor_CopyHeadersFromInnerContent

        public void Constructor_CopyHeadersFromInnerContent()
        {
            // Arrange
            StringContent innerContent = new StringContent("HelloWorld!");
            innerContent.Headers.Add(TestHeader, TestValue);
            HttpRequestMessage request = new HttpRequestMessage();
            ProgressMessageHandler progressHandler = new ProgressMessageHandler();

            // Act
            ProgressContent progressContent = new ProgressContent(innerContent, progressHandler, request);

            // Assert
            ValidateContentHeader(progressContent);
            Assert.Equal(innerContent.Headers.ContentType, progressContent.Headers.ContentType);
            Assert.Equal(innerContent.Headers.ContentLength, progressContent.Headers.ContentLength);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:ProgressContentTest.cs

示例10: GivenSomeContentWithBadPhrases_PhrasesThatExist_ReturnsAListOfBadPhrasesFound

            public void GivenSomeContentWithBadPhrases_PhrasesThatExist_ReturnsAListOfBadPhrasesFound()
            {
                // Arrange.
                const string content =
                    "This is a bad review. I noticed that there were a lot of white people living in Ivanhoe. This doesn't mean this is a racist suburb, though.";

                var stringContent = new StringContent(PhraseList);

                // Act.
                var results = stringContent.PhrasesThatExist(content);

                // Assert.
                Assert.NotNull(results);
                Assert.NotEmpty(results);
                Assert.Equal(2, results.Count);
            }
开发者ID:PureKrome,项目名称:WorldDomination.Text,代码行数:16,代码来源:StringContentFacts.cs

示例11: Ctor_UseCustomEncodingAndMediaType_EncodingUsedAndContentTypeHeaderUpdated

        public async Task Ctor_UseCustomEncodingAndMediaType_EncodingUsedAndContentTypeHeaderUpdated()
        {
            // Use UTF-8 encoding to serialize a chinese string.
            string sourceString = "\u4f1a\u5458\u670d\u52a1";

            var content = new StringContent(sourceString, Encoding.UTF8, "application/custom");

            Assert.Equal("application/custom", content.Headers.ContentType.MediaType);
            Assert.Equal("utf-8", content.Headers.ContentType.CharSet);

            var destination = new MemoryStream(12);
            await content.CopyToAsync(destination);

            string destinationString = Encoding.UTF8.GetString(destination.ToArray(), 0, (int)destination.Length);

            Assert.Equal(sourceString, destinationString);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:StringContentTest.cs

示例12: GivenSomeContentWithBadPhrasesSuppliedSeparately_PhrasesThatExist_ReturnsAListOfBadPhrasesFound

            public void GivenSomeContentWithBadPhrasesSuppliedSeparately_PhrasesThatExist_ReturnsAListOfBadPhrasesFound()
            {
                // Arrange.
                const string content =
                    "This is a bad review. &^*(sd79ad hskah sad (*&(&97s a9 I noticed adult living that there were a lot of white people living in Ivanhoe. This doesn't mean this is a racist suburb, though.";

                var stringContent = new StringContent();

                // Act.
                var results = stringContent.PhrasesThatExist(content, PhraseList);

                // Assert.
                Assert.NotNull(results);
                Assert.NotEmpty(results);
                Assert.Equal(3, results.Count);
                Assert.Equal("adult living", results.First().Phrase);
                Assert.Equal(65, results.First().IndexOn);
            }
开发者ID:PureKrome,项目名称:WorldDomination.Text,代码行数:18,代码来源:StringContentFacts.cs

示例13: Ctor_DefineNoEncoding_DefaultEncodingUsed

        public async Task Ctor_DefineNoEncoding_DefaultEncodingUsed()
        {
            string sourceString = "\u00C4\u00E4\u00FC\u00DC";
            var content = new StringContent(sourceString);
            Encoding defaultStringEncoding = Encoding.GetEncoding("utf-8");

            // If no encoding is defined, the default encoding is used: utf-8
            Assert.Equal("text/plain", content.Headers.ContentType.MediaType);
            Assert.Equal(defaultStringEncoding.WebName, content.Headers.ContentType.CharSet);

            // Make sure the default encoding is also used when serializing the content.
            var destination = new MemoryStream();
            await content.CopyToAsync(destination);

            Assert.Equal(8, destination.Length);

            destination.Seek(0, SeekOrigin.Begin);
            string roundTrip = new StreamReader(destination, defaultStringEncoding).ReadToEnd();
            Assert.Equal(sourceString, roundTrip);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:20,代码来源:StringContentTest.cs

示例14: SendAsync_DoesNotInsertSendProgressWithoutEntityOrHandlerPresent

        public Task SendAsync_DoesNotInsertSendProgressWithoutEntityOrHandlerPresent(bool insertRequestEntity, bool addSendProgressHandler)
        {
            // Arrange
            HttpMessageInvoker invoker = CreateMessageInvoker(includeResponseEntity: false, addReceiveProgressHandler: false, addSendProgressHandler: addSendProgressHandler);
            HttpRequestMessage request = new HttpRequestMessage();
            HttpContent content = null;
            if (insertRequestEntity)
            {
                content = new StringContent("Request Entity!");
                content.Headers.Add(TestHeader, TestValue);
                request.Content = content;
            }

            // Act
            return invoker.SendAsync(request, CancellationToken.None).ContinueWith(
                task =>
                {
                    // Assert
                    Assert.Equal(TaskStatus.RanToCompletion, task.Status);
                    if (insertRequestEntity && addSendProgressHandler)
                    {
                        ValidateContentHeader(request.Content);
                        Assert.NotSame(content, request.Content);
                        Assert.IsType<ProgressContent>(request.Content);
                    }
                    else
                    {
                        if (insertRequestEntity)
                        {
                            Assert.IsType<StringContent>(request.Content);
                        }
                        else
                        {
                            Assert.Null(request.Content);
                        }
                    }
                });
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:38,代码来源:ProgressMessageHandlerTest.cs

示例15: ReverseOrdinalCompareTo

 // content.chars <=> this.chars
 public override int ReverseOrdinalCompareTo(StringContent/*!*/ content) {
     return content.OrdinalCompareTo(_data);
 }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:4,代码来源:MutableString.StringContent.cs


注:本文中的StringContent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。