Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Tweetsharp从url发送TweetWithMedia_C#_Tweetsharp - Fatal编程技术网

C# Tweetsharp从url发送TweetWithMedia

C# Tweetsharp从url发送TweetWithMedia,c#,tweetsharp,C#,Tweetsharp,我正在尝试使用Tweetsharp的SendTweetWithMedia和一个我没有存储在本地的图像,我只有一个url。我发现的所有SendTweetWithMedia示例都使用本地系统上的文件 var thumb = "http://somesite.net/imageurl"; var service = new TwitterService(key, secret); service.AuthenticateWith(token, tokenSecret); var req = WebRe

我正在尝试使用Tweetsharp的SendTweetWithMedia和一个我没有存储在本地的图像,我只有一个url。我发现的所有SendTweetWithMedia示例都使用本地系统上的文件

var thumb = "http://somesite.net/imageurl";
var service = new TwitterService(key, secret);
service.AuthenticateWith(token, tokenSecret);
var req = WebRequest.Create(thumb);
using (var stream = req.GetResponse().GetResponseStream())
{
    response = service.SendTweetWithMedia(new SendTweetWithMediaOptions
    {
    Status = tweet.Trim(),
    Images = new Dictionary<string, Stream> { { fullname, stream } }
    });
} 
var thumb=”http://somesite.net/imageurl";
var服务=新的推特服务(密钥、机密);
服务.AuthenticateWith(令牌、令牌机密);
var req=WebRequest.Create(thumb);
使用(var stream=req.GetResponse().GetResponseStream())
{
响应=服务。SendTweetWithMedia(新的SendTweetWithMedia选项
{
状态=tweet.Trim(),
Images=新字典{{fullname,stream}
});
} 
我从SendTweetWithMedia收到以下错误:

“System.NotSupportedException”:此流不支持查找操作


我可以从url下载文件并在本地保存,但我更愿意使用url。这可能吗?

最后,我刚刚创建了一个临时文件:

byte[] data;
using (var client = new WebClient())
{
    data = client.DownloadData(thumb);
}
File.WriteAllBytes($"{Path.GetTempPath()}\\xyz.jpg", data);

我能想出的最好的答案。不过还是比我想要的多了几行。

您可以检查读取流并将其存储到内存流,就像下面接受的回答中所示:谢谢,我尝试使用内存流,它确实做得更好。然而SendTweetWithMedia只是超时,大约1分钟后返回null。老实说,我也可以下载url并保存到本地文件,就像将所有内容转换为MemoryStream一样。至少那时我会站在大家都熟悉的地方。