0
我試圖通過我的vb.net應用程序使用blogger api作出新的職位。 但我每次都失敗。 有時它會返回403禁止的錯誤某些時候未經授權的錯誤。 請幫助。VB.NET - 如何使用Blogger API V3發佈到Blogspot?
Dim mBlogID As String = "5861877551002158183"
Dim AuthToken As String = "AIza......xxxx..........E6g"
Dim post As String = "{""kind"": ""blogger#post"", ""blog"": { ""id"": """ & mBlogID & """}, ""title"": ""abc-title"", ""content"": ""abc-cont""}"
Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://www.googleapis.com/blogger/v3/blogs/" & mBlogID & "/posts?key=" & AuthToken), HttpWebRequest)
request.Method = "POST"
request.ContentLength = post.Length
request.ContentType = "application/json"
request.Headers.Add("Authorization: ", AuthToken) '<--- error here
Using requestStream As Stream = request.GetRequestStream()
Dim postBuffer As Byte() = Encoding.ASCII.GetBytes(post)
requestStream.Write(postBuffer, 0, postBuffer.Length)
End Using
Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) '<--- Unauthorised error or 403 error here
Using responseStream As Stream = response.GetResponseStream()
Using responseReader As New StreamReader(responseStream)
'Dim json As String = responseReader.ReadToEnd()
'Dim PostURL As String = Regex.Match(json, """url"": ?""(?<id>.+)""").Groups("id").Value
MsgBox(json) 'want to read json response here.
'MsgBox(PostURL)
End Using
End Using
End Using
此代碼返回此錯誤:指定的值具有無效的HTTP標頭字符。 參數名稱:名稱
任何人都可以修復它嗎?我只想發一個新信息到blogger並閱讀它的URL。
項目信息: -
平臺:Visual Basic中2010
的Blogger API版本:V3
在你回答的時候,這個問題已經成爲了10個月的問題。目前我正在開展另一個項目,並將在後期尋找您的解決方案。謝謝。 –