Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 我需要帮助。。windows mobile 6 net cf 3.5的图片上传功能_.net_Vb.net_Windows Mobile_Compact Framework - Fatal编程技术网

.net 我需要帮助。。windows mobile 6 net cf 3.5的图片上传功能

.net 我需要帮助。。windows mobile 6 net cf 3.5的图片上传功能,.net,vb.net,windows-mobile,compact-framework,.net,Vb.net,Windows Mobile,Compact Framework,所有的运行都很完美,但让我最后一次紧张的是getstring部分。。 该函数非常完美,但我需要一种方法来找到getstring问题的替代方法。。 使用getstring(pic,0,pic.length)时,我变成了一个错误。。找不到出路大thx寻求帮助 代码如下: Public Function uploadPic(ByVal pic As Byte(), ByVal filename As String, ByVal user As String) Dim encoding As S

所有的运行都很完美,但让我最后一次紧张的是getstring部分。。 该函数非常完美,但我需要一种方法来找到getstring问题的替代方法。。 使用getstring(pic,0,pic.length)时,我变成了一个错误。。找不到出路大thx寻求帮助

代码如下:

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
终于找到了解决方案--更改编码:

Dim encoding As String = "iso-8859-2"
要解决“在写入请求数据之前无法检索此请求的响应”错误,应在调用
request.GetResponse()
之前关闭
writer
流,如下所示:

writer.Write(bytes, 0, bytes.Length)
writer.Close()
response = request.GetResponse()
您不必在桌面版的.net中执行此操作,但必须在.net compact framework中执行


我知道这是一个老问题,我的回答可能会被提问者忽略,但“在写下请求数据之前无法检索此请求的响应”谷歌搜索将我引向了这个问题。我希望它能帮助别人。

请指定问题或收到的异常。getstring(pic,0,pic.length)的错误是PlatformNotSupportedException屏幕截图:getstring(pic)的错误请参见屏幕截图:在pc上,它运行得很好,但在compact framework 3.5上,我找不到修复它的方法。readallbytes的问题已经解决了,但是现在我坚持这个问题。。我看了一篇文章,试了一下iso-8859-2。。现在他在getstring上没有麻烦了。。但是现在他在response=request.getresponse()--处停止,错误为:{“在写入请求数据之前无法检索此请求的响应。”}