简体   繁体   English

需要帮助.. Windows Mobile 6 net cf 3.5的图片上传器功能

[英]Need Help.. Picture uploader function for windows mobile 6 net cf 3.5

all runs perfect but the thing that cost me my last nervs is the getstring part .. that function is wonderfull but i need a way to find an alternative for the getstring problem.. with getstring(pic,0,pic.length) i became an error.. and find no way out big thx for help 一切运行完美,但是让我最后一个神经衰弱的是getstring部分..该功能很棒,但是我需要一种方法来找到getstring问题的替代方法..使用getstring(pic,0,pic.length)我成了一个错误..并没有办法寻求帮助

hers the code: 她的代码:

Public Function uploadPic(ByVal pic As Byte(), ByVal filename As String, ByVal user As String)
    Dim encoding As String = "iso-8859-1"
    'Erzeugen einer einzigartigen identifikation
    Dim gui As String = Guid.NewGuid().ToString()
    'Diese wird für den Header und den footer der Daten benötigt
    Dim head As String = String.Format("--{0}", gui)
    Dim foot As String = String.Format("--{0}--", gui)
    'Einen Stringbuilder erstellen, in dem wir nun bequem die
    'benötigten POST Daten speichern können
    Dim contents As StringBuilder = New StringBuilder()
    'Benutzerdaten schreiben (benutzername)
    contents.AppendLine(head)
    contents.AppendLine(String.Format("Content-Disposition: form-data; name=""{0}""", "username"))
    contents.AppendLine()
    contents.AppendLine(user)
    'Header schreiben
    contents.AppendLine(head)
    'Bildinformationen schreiben, Bildkopf und die Binärdaten
    Dim fileHeader As String = String.Format("Content-Disposition: file; name=""{0}""; filename=""{1}""", "media", user & ".jpg")
    Dim fileData As String = System.Text.Encoding.GetEncoding(encoding).GetString(pic)
    'Informationen zu dem Übergebenen Dateityp schreiben
    contents.AppendLine(fileHeader)
    contents.AppendLine(String.Format("Content-Type: {0}", "image/jpeg"))
    contents.AppendLine()
    contents.AppendLine(fileData)
    'Durch schreiben des footers signalisieren dass keine Daten mehr kommen
    contents.AppendLine(foot)
    'MessageBox.Show(contents.ToString)
    'Stream Reader zum lesen der Antwort von Twitpic
    Dim reader As StreamReader
    Dim result As String
    Dim response As HttpWebResponse
    'Einen Webrequest zu der TwitPic API erstellen
    Dim request As HttpWebRequest = WebRequest.Create("http://urspacecity.de/uploadpic/up.php")
    request.ContentType = String.Format("multipart/form-data; boundary={0}", gui)
    request.Method = "POST"
    'Die Daten die noch im Stringbuilder als String vorliegen
    'in das byte (Binär)-Format umwandeln, damit die API diese annimt
    Dim bytes As Byte() = System.Text.Encoding.GetEncoding(encoding).GetBytes(contents.ToString())
    request.ContentLength = bytes.Length
    'Einen Stream aus dem WebRequest erstellen
    Dim writer As Stream = request.GetRequestStream()
    'Die Binären Daten in den Strom schreiben
    writer.Write(bytes, 0, bytes.Length)
    response = request.GetResponse()
    reader = New StreamReader(response.GetResponseStream)
    result = reader.ReadToEnd
    reader.Close()

    Return result
End Function

Finally found the solution -- change the encoding: 终于找到了解决方法-更改编码:

Dim encoding As String = "iso-8859-2"

To solve "the response for this request cannot be retrieved until request data has been written" error, you should close the writer stream before calling request.GetResponse() , like this: 要解决“在写入请求数据之前无法检索此请求的响应”错误,您应在调用request.GetResponse()之前关闭writer流,如下所示:

writer.Write(bytes, 0, bytes.Length)
writer.Close()
response = request.GetResponse()

You don't have to do this in desktop version of .net but you have to in .net compact framework. 您不必在.net桌面版本中执行此操作,但必须在.net Compact Framework中执行此操作。

I know this is an old question, and my answer is likely be ignored by asker but "the response for this request cannot be retrieved until request data has been written" google search directed me to this question. 我知道这是一个古老的问题,我的答案很可能会被问问者忽略,但“在写入请求数据之前,无法检索到此请求的响应”,谷歌搜索将我引导至此问题。 I hope it helps someone. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM