|
-
Oct 4th, 2007, 12:45 PM
#1
Thread Starter
New Member
Upload through Post
I found much of the code here http://www.vbforums.com/showthread.php?t=472078
and it works just fine for imagevenue. I'm trying to change that code and make it workable for xxxxxxxxxxxxxxxxxx (adult image host please do not visit with kids around or if you are a kid).
Below is my vb.net code that posts to the website, the raw headers from uploading through a normal browser and through the use of this code.
It just doesn't seem to work, and I've been staring at it now and changing things for days. Hope someone can point me in the right direction.
Much appreciated.
Code:
Private Sub bgw1_DoWork()
Dim boundary As String = ("-----------------------------" & DateTime.Now.Ticks.ToString("x"))
Dim Postheader() As Byte
Dim builder As New StringBuilder
builder.Append("--")
builder.Append(boundary)
builder.Append(ChrW(13) & ChrW(10))
builder.Append("Content-Disposition: form-data; name=""MAX_FILE_SIZE""")
builder.Append(ChrW(13) & ChrW(10))
builder.Append(ChrW(13) & ChrW(10))
builder.Append("1536000")
builder.Append(ChrW(13) & ChrW(10))
builder.Append("--")
builder.Append(boundary)
builder.Append(ChrW(13) & ChrW(10))
builder.Append("Content-Disposition: form-data; name=""imagename[]""")
builder.Append(ChrW(13) & ChrW(10))
builder.Append(ChrW(13) & ChrW(10))
builder.Append(ChrW(13) & ChrW(10))
builder.Append("--")
builder.Append(boundary)
builder.Append(ChrW(13) & ChrW(10))
builder.Append("Content-Disposition: form-data; name=""images[]""; filename=""")
'builder.Append(Path.GetFileName(filepath1))
builder.Append(filepath1)
builder.Append("""")
builder.Append(ChrW(13) & ChrW(10))
builder.Append("Content-Type: ")
builder.Append("image/jpeg")
builder.Append(ChrW(13) & ChrW(10))
builder.Append(ChrW(13) & ChrW(10))
Postheader = Encoding.UTF8.GetBytes(builder.ToString)
Dim myStream As FileStream = Nothing
Dim requestStream As Stream = Nothing
Dim myResponse As HttpWebResponse = Nothing
Dim myReader As StreamReader = Nothing
Dim Cookies As CookieCollection
Try
'Dim aRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.freeporndumpster.com/index.php"), HttpWebRequest)
'Dim aResponse As HttpWebResponse = DirectCast(aRequest.GetResponse, HttpWebResponse)
Dim myRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.freeporndumpster.com/index.php"), HttpWebRequest)
'Dim aResponse As HttpWebResponse = DirectCast(myRequest.GetResponse, HttpWebResponse)
'aResponse.Close()
myRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
myRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")
myRequest.Headers.Add("UA-CPU", "x86")
myRequest.Headers.Add("Accept-Encoding", "gzip, deflate")
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; IEMB3; IEMB3)"
myRequest.ContentType = ("multipart/form-data; boundary=" & boundary)
myRequest.Headers.Add(HttpRequestHeader.Pragma, "no-cache")
myRequest.KeepAlive = True
myRequest.Referer = "http://www.xxxxxxxxxxxxxx.com/"
myRequest.CookieContainer = New CookieContainer()
Dim myCookie As Cookie = New Cookie()
myCookie.Domain = "www.xxxxxxxxxxxxxxxr.com"
myCookie.Name = "from"
myCookie.Value = "noref"
myRequest.CookieContainer.Add(myCookie)
myCookie.Name = "PHPSESSID"
'myCookie.Value = aResponse.Headers.Item(7).Substring(10, 32)
myCookie.Value = "6e5e787dd4db28439ef27e2f7854f67e"
myRequest.CookieContainer.Add(myCookie)
myCookie.Name = "from"
myCookie.Value = "noref"
myRequest.CookieContainer.Add(myCookie)
myRequest.ServicePoint.Expect100Continue = False
myRequest.Method = "POST"
myRequest.AllowWriteStreamBuffering = True
Dim bytes As Byte() = Encoding.ASCII.GetBytes((ChrW(13) & ChrW(10) & "--" & boundary & "--" & ChrW(13) & ChrW(10)))
myStream = New FileStream(filepath1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim taille As Long = ((Postheader.Length + myStream.Length) + bytes.Length)
myRequest.ContentLength = taille
requestStream = myRequest.GetRequestStream
' Send first information before image
requestStream.Write(Postheader, 0, Postheader.Length)
Const BufferSize As Integer = 4096
Dim content As Byte() = New Byte(BufferSize - 1) {}
Dim dataRead As Integer
Dim dataReads As Long = 0
' Send image
While True
dataRead = myStream.Read(content, 0, BufferSize)
If dataRead = 0 Then
Exit While
End If
requestStream.Write(content, 0, dataRead)
dataReads += dataRead
'bgw1.ReportProgress(Math.Round(CDbl((dataReads / myStream.Length) * 100), 0))
End While
' Send info after image
requestStream.Write(bytes, 0, bytes.Length)
requestStream.Close()
requestStream.Dispose()
myStream.Close()
myStream.Dispose()
myResponse = DirectCast(myRequest.GetResponse, HttpWebResponse)
myReader = New StreamReader(myResponse.GetResponseStream, Encoding.UTF8)
Dim myResult As String = myReader.ReadToEnd
myResponse.Close()
myReader.Close()
myReader.Dispose()
If myResult.Contains("successfully") Then
If (myResult.Contains("[url=http://") AndAlso myResult.Contains("[/URL]")) Then
myResult = myResult.Substring(myResult.IndexOf("[url=http://"))
myResult = myResult.Remove((myResult.IndexOf("[/URL]", 0) + 6))
ElseIf (myResult.Contains("")) Then
myResult = myResult.Substring(myResult.IndexOf("", 0) + 6)
End If
result1 = myResult
End If
Catch exception As Exception
Finally
Try
If (Not requestStream Is Nothing) Then
requestStream.Close()
requestStream.Dispose()
End If
If (Not myStream Is Nothing) Then
myStream.Close()
myStream.Dispose()
End If
If (Not myResponse Is Nothing) Then
myResponse.Close()
myResponse = Nothing
End If
If (Not myReader Is Nothing) Then
myReader.Close()
myReader.Dispose()
End If
Catch 'obj2 As Object
End Try
End Try
End Sub
I am using Fiddler to check the Request Headers, and my code generated header is near identical to the Sites Header.
My Post Header
Code:
POST /index.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; IEMB3; IEMB3)
Content-Type: multipart/form-data; boundary=-----------------------------8c9d4a29023ab34
Pragma: no-cache
Referer: xxxxxxxxxxxxxxxx
Host: xxxxxxxxxxxxxxxxxx
Cookie: from=noref; PHPSESSID=6e5e787dd4db28439ef27e2f7854f67e
Content-Length: 278559
Proxy-Connection: Keep-Alive
-------------------------------8c9d4a29023ab34
Content-Disposition: form-data; name="MAX_FILE_SIZE"
1536000
-------------------------------8c9d4a29023ab34
Content-Disposition: form-data; name="imagename[]"
-------------------------------8c9d4a29023ab34
Content-Disposition: form-data; name="images[]"; filename="C:\temp\work\test1.jpg"
Content-Type: image/pjpeg
The Site Header
Code:
POST /index.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: xxxxxxxxxxxxxxxxx
Accept-Language: en-us
Content-Type: multipart/form-data; boundary=---------------------------7d72cec207c0
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; IEMB3; IEMB3)
Proxy-Connection: Keep-Alive
Content-Length: 288770
Host: xxxxxxxxxxxxxxx
Pragma: no-cache
Cookie: from=noref; PHPSESSID=6e5e787dd4db28439ef27e2f7854f67e; from=noref
-----------------------------7d72cec207c0
Content-Disposition: form-data; name="MAX_FILE_SIZE"
1536000
-----------------------------7d72cec207c0
Content-Disposition: form-data; name="imagename[]"
-----------------------------7d72cec207c0
Content-Disposition: form-data; name="images[]"; filename="C:\temp\work\test.jpg"
Content-Type: image/pjpeg
Last edited by Hack; Oct 4th, 2007 at 12:50 PM.
-
Oct 4th, 2007, 02:35 PM
#2
Thread Starter
New Member
Re: Upload through Post
This works against other hosts, but SPECIFICALLY not the one I've trying to get help with.
PM if you want to try this code against the specific site that they have xxx out above.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|