无法使用RestSharp将图像上传到Twitter

时间:2012-06-25 16:59:41

标签: twitter windows-runtime twitter-oauth restsharp

我正在尝试使用RestSharp将WinRT应用程序中的图像上传到twitter 代码在这里:

RestClient twClient = new RestClient("https://upload.twitter.com");
twClient.Authenticator = OAuth1Authenticator.ForProtectedResource(........);
var postTweet = new RestRequest("/1/statuses/update_with_media.json", Method.POST);
postTweet.AddParameter("status", TweetBox.Text);
byte[] img = await GetDataAsync(imageFile);
postTweet.AddFile("media[]", img, imageFile.Name, "multipart/form-data");            
twClient.ExecuteAsync(postTweet, (response =>
{
     try
     {
          if (response.StatusCode == HttpStatusCode.OK) 
          {
              ....

这是我的GetDataAsync,它从隔离存储中的文件中获取字节数组

    public static async Task<byte[]> GetDataAsync(StorageFile file)
    {
        IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
        DataReader reader = new DataReader(stream.GetInputStreamAt(0));

        uint streamSize = (uint)stream.Size;
        await reader.LoadAsync(streamSize);
        byte[] buffer = new byte[streamSize];
        reader.ReadBytes(buffer);
        return buffer;
    }

服务器响应:

Expectation Failed
The expectation given in the Expect request-header field could not be met by this server.
The client sent
Expect: 100-continue
but we only allow the 100-continue expectation.

0 个答案:

没有答案