为什么这段代码不起作用? [英] why this code not work?

查看:46
本文介绍了为什么这段代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Private Sub Button1_Click(发件人为对象,e为EventArgs)处理Button1.Click 
Dim ImageBinary()As 字节
Dim Header1 As Byte ,Header2 As 字符串
Dim BHeader1()As Byte ,BHeader2()As Byte , Buffer()As Byte
Dim boundary As String
Dim fPath As String ,fName As String
Dim Headers As String
Dim X As New Collection
Dim wbody As Byte

wbody = TextBox1.Text
fPath = C:\ Users \ 형민\Desktop\이미지업로드\
FNAME = DIR(fPath&安培;
*。jpg

Do Len(fName)
X.Add(fName,fName)
fName = Dir $()
循环


boundary =
26036217909135


fName = X( Int(Rnd()* X.Count + 1))

ImageBinary = IO.File.ReadAllBytes(fPath& fName)
BHeader1 = System.Text.Encoding.Default.GetBytes(拆分(wbody,
wBinary )(0))
BHeader2 = System.Text。 Encoding.Default.GetBytes(Split(wbody,
wBinary )(1))

Dim DS As New MemoryStream
DS.Write(BHeader1,0,BHeader1.Length)
DS.Write(ImageBinary,0,ImageBinary.Length)
DS.Write(BHeader2 ,0,BHeader2.Length)
DS.Position = 0
ReDim Buffer (DS.Length)
DS.Read(Buffer,0,Buffer.Length):DS.Close()
使用WinHttp
。打开(
POST http: // imgdb.kilho.net/upload.php)
.SetRequestHeader( User-Agent Mozilla / 5.0(Windows NT 6.1; rv:43.0)Gecko / 20100101 Firefox / 43.0
.SetRequestHeader( Referer http://image.kilho.net
。 SetRequestHeader( Content-Type multipart / form-data; boundary = ---------------------------& boundary)
.SetRequestHeader( Content-Length,UBound(Buffer) )
.Send(Buffer)
.WaitForResponse():Application.DoEvents()
Headers = .GetAllResponseHeaders
MsgBox(.ResponseText)

End
End Sub





但服务器消息你没有权限访问upload.php服务器

为什么..?

解决方案

()
循环


boundary = 26036217909135


fName = X(Int(Rnd()* X.Count + 1))

ImageBinary = IO.File.ReadAllBytes(fPath& fName)
BHeader1 = System.Text.Encoding.Default.GetBytes(Split(wbody,
wBinary )(0))
BHeader2 = System.Text.Encoding.Default.GetBytes(Split(wbody,
wBinary < span class =code-string>)(1))

Dim DS As New MemoryStream
DS.Write(BHeader1,0,BHeader1.Length)
DS.Write (ImageBinary,0,ImageBinary.Length)
DS.Write(BHeader2,0,BHeader2.Length)
DS.Position = 0
ReDim Buffer(DS.Length)
DS .Read(Buffer,0,Buffer.Length):DS.Close()
使用WinHttp
。打开( POST http: // imgdb.kilho.net /upload.php)
.SetRequestHeader( User-Agent Mozilla / 5.0(Windows NT 6.1; rv:43.0)Gecko / 20100101 Firefox / 43.0
.SetRequestHeader( Referer http://image.kilho.net
。 SetRequestHeader( Content-Type multipart / form-data; boundary = ---------------------------& boundary)
.SetRequestHeader( Content-Length,UBound(Buffer) )
.Send(Buffer)
.WaitForResponse():Application.DoEvents()
Headers = .GetAllResponseHeaders
MsgBox(.ResponseText)

End
End Sub





但服务器消息你没有权限访问upload.php服务器

为什么..?


错误消息e很明确:

你没有权限访问upload.php服务器



最有可能原因是您不是正确的用户:您正在尝试访问特定用户桌面,除非您具有提升的权限,或者您是该用户,系统将阻止您。由于这似乎是基于Web的代码,因此它可能是在IIS下运行而不是作为您的用户身份。



而不是尝试将其保存到特定用户,要么在服务器上创建一个每个人都可以访问的文件夹(危险),要么使用Server.MapPath访问网站根目录下的文件夹来保存文件。


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim ImageBinary() As Byte
    Dim Header1 As Byte, Header2 As String
    Dim BHeader1() As Byte, BHeader2() As Byte, Buffer() As Byte
    Dim boundary As String
    Dim fPath As String, fName As String
    Dim Headers As String
    Dim X As New Collection
    Dim wbody As Byte

    wbody = TextBox1.Text
    fPath = "C:\Users\변형민\Desktop\이미지 업로드\"
    fName = Dir(fPath & "*.jpg")

    Do While Len(fName)
        X.Add(fName, fName)
        fName = Dir$()
    Loop


    boundary = "26036217909135"


    fName = X(Int(Rnd() * X.Count + 1))

    ImageBinary = IO.File.ReadAllBytes(fPath & fName)
    BHeader1 = System.Text.Encoding.Default.GetBytes(Split(wbody, "wBinary")(0))
    BHeader2 = System.Text.Encoding.Default.GetBytes(Split(wbody, "wBinary")(1))

    Dim DS As New MemoryStream
    DS.Write(BHeader1, 0, BHeader1.Length)
    DS.Write(ImageBinary, 0, ImageBinary.Length)
    DS.Write(BHeader2, 0, BHeader2.Length)
    DS.Position = 0
    ReDim Buffer(DS.Length)
    DS.Read(Buffer, 0, Buffer.Length) : DS.Close()
    With WinHttp
        .Open("POST", "http://imgdb.kilho.net/upload.php")
        .SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0")
        .SetRequestHeader("Referer", "http://image.kilho.net")
        .SetRequestHeader("Content-Type", "multipart/form-data; boundary=---------------------------" & boundary)
        .SetRequestHeader("Content-Length", UBound(Buffer))
        .Send(Buffer)
        .WaitForResponse() : Application.DoEvents()
        Headers = .GetAllResponseHeaders
        MsgBox(.ResponseText)

    End With
End Sub



but server message "you don't have permission acess upload.php server"
why..?

解决方案

() Loop boundary = "26036217909135" fName = X(Int(Rnd() * X.Count + 1)) ImageBinary = IO.File.ReadAllBytes(fPath & fName) BHeader1 = System.Text.Encoding.Default.GetBytes(Split(wbody, "wBinary")(0)) BHeader2 = System.Text.Encoding.Default.GetBytes(Split(wbody, "wBinary")(1)) Dim DS As New MemoryStream DS.Write(BHeader1, 0, BHeader1.Length) DS.Write(ImageBinary, 0, ImageBinary.Length) DS.Write(BHeader2, 0, BHeader2.Length) DS.Position = 0 ReDim Buffer(DS.Length) DS.Read(Buffer, 0, Buffer.Length) : DS.Close() With WinHttp .Open("POST", "http://imgdb.kilho.net/upload.php") .SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:43.0) Gecko/20100101 Firefox/43.0") .SetRequestHeader("Referer", "http://image.kilho.net") .SetRequestHeader("Content-Type", "multipart/form-data; boundary=---------------------------" & boundary) .SetRequestHeader("Content-Length", UBound(Buffer)) .Send(Buffer) .WaitForResponse() : Application.DoEvents() Headers = .GetAllResponseHeaders MsgBox(.ResponseText) End With End Sub



but server message "you don't have permission acess upload.php server"
why..?


The error message is pretty explicit:

you don't have permission acess upload.php server


The most likely reason is that you aren't the right user: You are trying to access a specific users Desktop, and unless you have elevated permissions or you are that user the system is going to stop you. And since this seems to be web based code, the chances are that it is running under IIS rather than as your user identity.

Instead of trying to save it to a specific user, either have a folder created on the server that everyone can access (dangerous), or use Server.MapPath to access a folder under your website root directory to hold the file(s).


这篇关于为什么这段代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆