Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Beeting Head Against a wall

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-11-2008, 03:19 PM
Junior Member
 
Join Date: Mar 2008
Posts: 33
Thumbs up Beeting Head Against a wall

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
Code:
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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


All times are GMT. The time now is 02:17 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0