Beeting Head Against a wall

bish0p

Member
Licensed User
Longtime User
I have been fighting with uploading a file via multipart/form-data encoding.. with no Success.

I have sniffed IE, and firefox, and can't figure out what my code is sending that gets the post upload completely ignored
B4X:
Sub gc_upload_file()
   boundary="---------------------------7d822f2017079e"

   wwwreq.New1("http://www.geocaching.com/my/uploadfieldnotes.aspx")
   wwwreq.AddHeader("Cookie","ASP.NET_SessionId="&Session_ID)
   wwwres.Value = wwwreq.GetResponse

   tmp=wwwres.GetString
   regex.New1("id="&Chr(34)&"__VIEWSTATE"&Chr(34)&" value="&Chr(34)&".*"&Chr(34))
   match.Value=regex.Match(tmp)
   Viewstate=match.String
   'Viewstate=SubString(tmp,StrIndexOf(tmp,"id="&Chr(34)&"__VIEWSTATE"&Chr(34)&" value="&Chr(34),0)+24,4096)
   Viewstate=SubString(Viewstate,24,StrLength(Viewstate)-25)
   
   wwwreq.New1("http://www.geocaching.com/my/uploadfieldnotes.aspx")
   wwwreq.Method="POST"
   wwwreq.UserAgent="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1"
   wwwreq.AddHeader("Cookie","ASP.NET_SessionId="&Session_ID)
   wwwreq.Accept="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
   wwwreq.AddHeader("Accept-Encoding","gzip, deflate")
   
    obj.New1(false)
    obj.FromLibrary("wwwreq","req",B4PObject(2))
      obj.SetProperty("Referer","http://www.geocaching.com/my/uploadfieldnotes.aspx")
   wwwreq.KeepAlive=TRUE
   wwwreq.ContentType = "multipart/form-data; boundary="&boundary
   
   
   s=boundary&crlf&"Content-Disposition: form-data; name="&Chr(34)&"__VIEWSTATE"&Chr(34)&crlf&crlf
   s=s&Viewstate&crlf
   s=s&boundary&crlf
   s=s&"Content-Disposition: form-data; name="&Chr(34)&"fileUpload"&Chr(34)&"; filename="&Chr(34)&"c:\geocache_visits.txt"&Chr(34)&crlf
   s=s&"Content-Type: text/plain"&crlf&crlf
   
   totalfilesize = FileSize(AppPath&"\geocache_visits.txt")
   FileOpen (c1,AppPath&"\geocache_visits.txt",cRandom)
   r=FileGet(c1,0,totalfilesize)
   'reader.New1(c1,false)
   'count=reader.ReadBytes(buffer2(),totalfilesize)
   
   s=s&r&boundary&crlf
   s=s&"Content-Disposition: form-data; name="&Chr(34)&"btnUpload"&Chr(34)&crlf&crlf
   s=s&"Upload"&crlf
   s=s&boundary&"--"&crlf

   buffer() = bit.StringToBytes(s,0,StrLength(s))    
   wwwreq.ContentLength = ArrayLen(buffer())
   
   writer.New1(wwwreq.GetStream,false)
        writer.WriteBytes(buffer())
   wwwres.Value = wwwreq.GetResponse

End Sub

Any Help would be great.
 
Top