http://hi.baidu.com/matrix286/item/b9e88b28b90707c9ddf69a6e
————————————————————————————————————————————————
SWT 的 org.eclipse.swt.browser.Browser类中有一个setUrl(String url, String postData, String[] headers)方法。我们可以通过这个方法进行submit数据。
例如:可以通过这个方法,进行用户登陆操作。(登陆成功后页面会自动跳转至登陆成功页面)
参数详解:setUrl(String url, String postData, String[] headers)
url:表示一个要post提交的数据地址。相当于Html中form表单中的action属性postData:表示提交的数据。如果是多个数据需要用&符号分开。例如:name=xiaobaitu&password=12345678headers:表示提交时http的Headers信息。
部分代码实例如下: String url = "http://127.0.0.1/webpages/login.jsp" String postData = "name=xiaobaitu&password=12345678"; String[] headers = { "Accept: */*", "Accept-Language: zh-cn", "Content-Type: application/x-www-form-urlencoded", // 建议要有 "Accept-Encoding: gzip, deflate", "Cache-Control: no-cache" };
browser.setUrl(url, postData, headers); 注意: (1) headers中的 "Content-Type: application/x-www-form-urlencoded"建议要有哦~~ (2) 如果提交的数据postData中包含中文, 则需要对其进行url编码。 例如:如果按照UTF-8编码,则是URLEncoder.encode(name, "UTF-8");
转载于:https://www.cnblogs.com/cuizhf/p/3721664.html
