1

我正在尝试使用 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.
4

0 回答 0