Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT-WebBrowser Control: PostData problem
SWT-WebBrowser Control: PostData problem [message #449662] Thu, 27 January 2005 16:24
Sergio Aranda is currently offline Sergio ArandaFriend
Messages: 2
Registered: July 2009
Junior Member
Hi, i have a problem with method Navigation of WebBrowser control using
the swt-activeX layer. When i send a x-www-form-ulrencoded data to a web
application, the native final string character \0 is always sent. This
make that the last parameter arrives malformed to the servlet.

This is the code to build the PostData param (extracted in part from a
walkarround of bug 10977):

<CODE SNIP>
private int makeSafeArray(String string) {
if ((string == null) || (string.length() == 0))
new IllegalArgumentException("string is null or empty");

// Here I create a one dimensional safearray containing two VT_UI1
// values
// where VT_UI1 is an unsigned char

// SAFEARRAY looks like this:
// short cDims // Count of dimensions in this array
// short fFeatures // Flags used by the SafeArray
// int cbElements // Size of an element of the array
// int cLocks // Number of times the array has been locked
without
// corresponding unlock
// int pvData // Pointer to the data
// SAFEARRAYBOUND[] rgsabound // One bound for each dimension
// SAFEARRAYBOUND looks like this:
// int cElements // the number of elements in the dimension
// int lLbound // the lower bound of the dimension

//step 1 - define cDims, fFeatures and cbElements
short cDims = 1;
short FADF_FIXEDSIZE = 0x10;
short FADF_HAVEVARTYPE = 0x80;
short fFeatures = (short) (FADF_FIXEDSIZE | FADF_HAVEVARTYPE);
int cbElements = 1;
int pvData;
int cElements1;
//create a pointer and copy the data into it
int count = string.length();
char[] chars = new char[count+1];
string.getChars(0, count, chars, 0);
int cchMultiByte = OS.WideCharToMultiByte(CodePage, 0, chars, -1,
null,
0, null, null);
pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
cchMultiByte);
OS.WideCharToMultiByte(CodePage, 0, chars, -1, pvData,
cchMultiByte,
null, null);
cElements1 = cchMultiByte;

int lLbound1 = 0;
//step 3 - create a safearray in memory
// 12 bytes for cDims, fFeatures and cbElements + 4 bytes for
pvData +
// number of dimensions * (size of safearraybound)
int sizeofSafeArray = 12 + 4 + 1 * 8;
int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
sizeofSafeArray);
//step 4 copy all the data into the safe array
int offset = 0;
OS.MoveMemory(pSafeArray + offset, new short[] { cDims }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new short[] { fFeatures }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new int[] { cbElements }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { pvData }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { cElements1 }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { lLbound1 }, 4);
offset += 4;

//step 5 create a variant in memory to hold the safearray
// VARIANT looks like this:
// short vt
// short wReserved1
// short wReserved2
// short wReserved3
// int parray
int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
Variant.sizeof);
short vt = (short) (OLE.VT_ARRAY | OLE.VT_UI1);
OS.MoveMemory(pVariant, new short[] { vt }, 2);
OS.MoveMemory(pVariant + 8, new int[] { pSafeArray }, 4);
return pVariant;
}
</CODE SNIP>

And this other code is to make the call to WebBrowser control navigate
method:

<CODE SNIP>
private boolean navigate(String url, Variant postdata) {
//checkWidget();
if (url == null)
new IllegalArgumentException("url is null");
if (postdata == null)
new IllegalArgumentException("postData is null");
int[] rgdispid = m_auto.getIDsOfNames(new String[] { "Navigate2",
"URL", "PostData", "Headers" });

Variant[] rgvarg = new Variant[3];
rgvarg[0] = new Variant(url);
int[] rgdispidNamedArgs = new int[3];
rgdispidNamedArgs[0] = rgdispid[1];
rgvarg[1] = postdata;
rgdispidNamedArgs[1] = rgdispid[2];
rgvarg[2] = new Variant(
"Content-Type: application/x-www-form-urlencoded\r\n");
rgdispidNamedArgs[2] = rgdispid[3];

Variant pVarResult = m_auto.invoke(rgdispid[0], rgvarg,
rgdispidNamedArgs);
if (pVarResult != null)
return pVarResult.getType() == OLE.VT_EMPTY;
else
return false;
}
</CODE SNIP>


I have make the same test but with c++ code and it works ok. Can anyone
tell me what is wrong in this java code? THANKS A LOT!!!!
Previous Topic:Browser widget: Popup Blocking with VisibilityWindowListener or OpenWindowListener?
Next Topic:How to combine scrolledComposite and Rowlayout ?
Goto Forum:
  


Current Time: Thu Nov 14 09:44:08 GMT 2019

Powered by FUDForum. Page generated in 0.01729 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top