417エラーのため投稿することができませんでしTwitterのC#クライアント

StackOverflow https://stackoverflow.com/questions/2002146

  •  18-09-2019
  •  | 
  •  

質問

私は私は何の問題も細かい投稿することができません自宅で最初からなくて、私の64ビットマシン上でTwitterクライアントを作成していますが、私はつぶやきを投稿するために来たときに私の32ビットのラップトップ上で、私は、エラー417を取得しています。

私はちょうどそれは私も何人かの人々がどんな運

なしaccuringからエラーを停止すると、以下に置いてきた問題であると思われる投稿、罰金のつぶやきを読むことができています
        System.Net.ServicePointManager.Expect100Continue = false;

私は他の誰がどんな考えを持っているものを次に何をするにはわからないのですか?投稿用のコードは以下の通りです。

おかげでマット

       string aUrl = "http://twitter.com/statuses/update.xml";

        client.Credentials = new NetworkCredential(_username, _password);

        System.Net.ServicePointManager.Expect100Continue = false;

        byte[] tweetBytes = System.Text.Encoding.UTF8.GetBytes("status=" + tweet);

        client.UploadData(aUrl,tweetBytes);

        return true;
役に立ちましたか?

解決

あなたは http://github.com/erans/twitter-csharpを見てみる必要があります-libraryする

このスニペットはgithubの上のtwitter.csファイルから取られました。

    /// <summary>
    /// Executes an HTTP POST command and retrives the information.     
    /// This function will automatically include a "source" parameter if the "Source" property is set.
    /// </summary>
    /// <param name="url">The URL to perform the POST operation</param>
    /// <param name="userName">The username to use with the request</param>
    /// <param name="password">The password to use with the request</param>
    /// <param name="data">The data to post</param> 
    /// <returns>The response of the request, or null if we got 404 or nothing.</returns>
    protected string ExecutePostCommand(string url, string userName, string password, string data) {
        System.Net.ServicePointManager.Expect100Continue = false;

        WebRequest request = WebRequest.Create(url);
        if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) {
            request.Credentials = new NetworkCredential(userName, password);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            if (!string.IsNullOrEmpty(TwitterClient)) {
                request.Headers.Add("X-Twitter-Client", TwitterClient);
            }

            if (!string.IsNullOrEmpty(TwitterClientVersion)) {
                request.Headers.Add("X-Twitter-Version", TwitterClientVersion);
            }

            if (!string.IsNullOrEmpty(TwitterClientUrl)) {
                request.Headers.Add("X-Twitter-URL", TwitterClientUrl);
            }


            if (!string.IsNullOrEmpty(Source)) {
                data += "&source=" + HttpUtility.UrlEncode(Source);
            }

            byte[] bytes = Encoding.UTF8.GetBytes(data);

            request.ContentLength = bytes.Length;
            using (Stream requestStream = request.GetRequestStream()) {
                requestStream.Write(bytes, 0, bytes.Length);

                using (WebResponse response = request.GetResponse()) {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                        return reader.ReadToEnd();
                    }
                }
            }
        }

        return null;
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top