我正在创建一个没有从头开始的Twitter客户端,在我家的64位机器上我可以发布没问题,但在我的32位笔记本电脑上,当我发布推文时,我收到错误417。
我能够阅读推文很好,只是张贴这似乎是一个问题我也在下面提到了一些人说停止错误没有任何运气
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;
答案 0 :(得分:0)
你应该看看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;
}