如何使用ASP.NET API发布特殊字符推文? [英] How to post the special characters tweets using ASP.NET API?

查看:98
本文介绍了如何使用ASP.NET API发布特殊字符推文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在C#中实现了以下给定的推文代码。但任何特殊字符(',!#@ $ etc)都会出现在标题中,推文不会在Twitter上发布。



我尝试过:



我试过以下代码。



Hi,

I implemented the given below code for tweets in C#. But any special character (',!#@$ etc) is come in the title, tweet is not published on twitter.

What I have tried:

I tried given below code.

using (WebClient client = new WebClient())
               {
                   client.DownloadFile(imagePath, localFilename);
               }
               var service = new TweetSharp.TwitterService(key, secret);
               service.AuthenticateWith(token, tokenSecret);

               // Tweet wtih image
               if (imagePath.Length > 0)
               {
                   using (var stream = new FileStream(localFilename, FileMode.Open))
                   {
                       var result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
                       {
                           Status = message,
                           Images = new Dictionary<string, Stream> { { "nkt", stream } }
                       });
                       Response.Write(result);
                   }
               }

推荐答案

等)在标题中出现,推文未在Twitter上发布。< br $> b $ b

我尝试了什么:



我试过下面的代码。



etc) is come in the title, tweet is not published on twitter.

What I have tried:

I tried given below code.

using (WebClient client = new WebClient())
               {
                   client.DownloadFile(imagePath, localFilename);
               }
               var service = new TweetSharp.TwitterService(key, secret);
               service.AuthenticateWith(token, tokenSecret);

               // Tweet wtih image
               if (imagePath.Length > 0)
               {
                   using (var stream = new FileStream(localFilename, FileMode.Open))
                   {
                       var result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
                       {
                           Status = message,
                           Images = new Dictionary<string, Stream> { { "nkt", stream } }
                       });
                       Response.Write(result);
                   }
               }


You can install the Microsoft.AspNet.WebApi.Client NuGet package on the client you could directly use the new HttpClient class (which is the new kid on the block) to consume your WebAPI instead of WebClient:
Sample implementation will be like below

Animal a = new Animal();
a.Message = "öçşistltl";
var URI = "http://localhost/Values/DoSomething";
using (var client = new HttpClient())
{
    client
        .PostAsync<Animal>(URI, a, new JsonMediaTypeFormatter())
        .ContinueWith(x => x.Result.Content.ReadAsStringAsync().ContinueWith(y =>
        {
            Console.WriteLine(y.Result);
        }))
        .Wait();
}


这篇关于如何使用ASP.NET API发布特殊字符推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆