3
我試圖發送圖像到Imgur的服務器。 一切都很順利,我從解析器獲取圖像的URL,但是當我試圖在Web瀏覽器上打開它時,我沒有得到圖像...只有一個「破碎的圖像」圖標。Imgur API和VB.NET的幫助 - 圖像POST
我認爲這是轉換爲字節數組的問題......但我不明白。請讓我知道/修復我的代碼。
Dim image As Image = image.FromFile(OpenFile.FileName)
Dim ms As New MemoryStream()
' Convert Image to byte[]
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageBytes As Byte() = ms.ToArray()
Dim wb As WebRequest = WebRequest.Create(New Uri("http://imgur.com/api/upload.xml"))
wb.ContentType = "application/x-www-form-urlencoded"
wb.Method = "POST"
wb.Timeout = 10000
Console.WriteLine(imageBytes.Length)
Dim parameters As String = "key=a801fa0b08a2117f5bb62b006f769b99&image=" + Convert.ToBase64String(imageBytes)
Dim encoding As New System.Text.UTF8Encoding()
Dim bytes As Byte() = encoding.GetBytes(parameters)
Dim os As System.IO.Stream = Nothing
Try
wb.ContentLength = bytes.Length
os = wb.GetRequestStream()
os.Write(bytes, 0, bytes.Length)
Dim xmlData As String = POSThandling.makePOSTrequest("http://imgur.com/api/upload.xml", New String() {parameters})
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(xmlData)
Dim name As XmlNodeList = xmlDoc.GetElementsByTagName("original_image")
Dim imageText As String = (name(0).InnerText).ToString
messageText.Text = imageText.ToString
PanelUpload.Visible = False
UpImage.Enabled = True
SendMsg.Enabled = True
Finally
If Not (os Is Nothing) Then
End If
End Try