来自ASP.Net的Twitter帖子-出现错误 [英] Twitter post from ASP.Net - Getting Error
本文介绍了来自ASP.Net的Twitter帖子-出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我在从ASP.net将推文发布到Twitter时遇到问题.
我收到错误消息,为"远程服务器返回错误:(401)未经授权"
任何帮助都会很棒!
谢谢
GOVIND
来自新问题:
谢谢您的及时答复.
正如您所要求的,我已经给出了mypost消息,我的用户名和密码,
以下是我正在使用的代码
Hi !
I have a problem in posting tweets to Twitter from ASP.net.
I am getting error as "The remote server returned an error: (401) Unauthorized"
Any help would be great!
Thanx
GOVIND
MOVED FROM NEW QUESTION:
HI Thanks for the immediate reply..
As you have asked , i have given mypost message, my username and paswword ,
Following is the code i am using
Sub TwitIt(ByVal strUser As String, ByVal strPass As String, ByVal strMessage As String)
''this subroutine requires your ASP.NET page to have a label control with an ID of lblStatus
''create post variable for tweet
Dim strTweet As String = "status=" & Server.HtmlEncode(strMessage)
''convert post variable to byte array for transmission purposes
Dim bRequest As Byte() = System.Text.Encoding.ASCII.GetBytes(strTweet)
Try
''create HttpWebRequest to status update API resource
Dim objRequest As HttpWebRequest = WebRequest.Create("http://twitter.com/statuses/update.xml")
''pass basic authentication credentials
objRequest.Credentials = New NetworkCredential(strUser, strPass)
''set method to post and pass request as a form
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
''tell the server it will not receive a 100 Continue HTTP response
objRequest.ServicePoint.Expect100Continue = False
''set content length of request
objRequest.ContentLength = bRequest.Length
''capture the stream (content) of the request
Dim objStream As Stream = objRequest.GetRequestStream()
''put the bytes into request
objStream.Write(bRequest, 0, bRequest.Length)
''close the stream to complete the request
objStream.Close()
''uncomment line below to report success
''lblStatus.Text = "Tweet sent!"
''You can also capture the XML response Twitter sends back
''uncomment lines below to capture responses
Dim objResponse As WebResponse = objRequest.GetResponse()
Dim objReader As New StreamReader(objResponse.GetResponseStream())
lblStatus.Text = objReader.ReadToEnd()
Catch ex As Exception
''uncomment line below to report ASP.NET errors
lblStatus.Text = ex.Message
End Try
End Sub
请对此提供帮助..我哪里出错了,或者需要使用IIS设置做什么.
Pls help on this..where i went wrong or what needs to be done with the IIS settings.
推荐答案
猜测:您是否尝试过登录?还是以其他任何方式提供登录凭据?
At a guess: have you tried logging in? Or providing your login credentials in any other way?
这篇关于来自ASP.Net的Twitter帖子-出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文