Hi!
I'm currently developing an application that needs to perform a file upload and show the resulting web page on a new browser window.
I've been trying to using JExplorer to achieve it, but I still did not find any success with it.
I'm using a third party server, so I don't have access to the actual log files to try to understand what is going on. Nonetheless, I used a proxy to intercept successful (using the web page as initially intended) and unsucessful (using JExplorer on a Swing application) calls.
My current problem (in my understanding) is that even tough my "postData" string contains "Content-Type: multipart/form-data", the browser replaces it with "Content-Type: application/x-www-form-urlencoded". I'm also failing to present a valid cookie (that I do not know if it is necessary or not, unless I clear out the postData string issue).
Here are the headers for the unsuccessful request:
POST <omitted>
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: es
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; MDDR; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; FDM)
Host: <omitted>
Content-Length: 4873
Proxy-Connection: Keep-Alive
Pragma: no-cache
Proxy-Authorization: Basic <omitted>
And the headers for the successful request:
POST <omitted>
Host: <omitted>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: <omitted>
Cookie: JSESSIONID=ef0dee8902b969562cdb4dfc44de02e592e02047c9d7abe59287450d23430e8f.e3uKch8KaheQe38KchiKbNeNaxz0; style=null
Content-Type: multipart/form-data; boundary=---------------------------61822586228240
Content-Length: 4873
Have you ever been successful in automating a file upload POST request?
Is there any other way to achieve this other than using the navigate method?
Thanks in advance.
Regards,
Nuno Guerreiro
Hi Nuno,
Please try to use the Navigate2 method to send additional headers. You can get access to Navigate2 method using the following code:
Browser browser = new Browser();
Variant url = new Variant("http://www.google.com");
Variant headers = new Variant("Content-Type: application/x-www-form-urlencoded");
IWebBrowser2 iWebBrowser2 = (IWebBrowser2) browser.getBrowserPeer();
iWebBrowser2.navigate2(url,
Variant.createUnspecifiedParameter(),
Variant.createUnspecifiedParameter(),
Variant.createUnspecifiedParameter(),
headers);
Regards,
Vladimir Ikryanov