如何使用jSessionId将多个edittext数据发布到网页上 [英] how to post multiple edittext data to a webpage with jSessionId
问题描述
我是Android开发的新手.
I'm new to Android development.
基本上,我需要将android应用程序的3 editTexts数据提交到网页并显示返回的响应. 该网页使用带有jSessionId的会话.
Basically I need to submit data from 3 editTexts of my android app to a webpage and display the response returned. The webpage uses sessions with jSessionId.
我不知道如何通过将jSessionId附加到url发送上述数据的同时,将请求发布到网页,获取cookie,存储并使用它. 我过去2天一直在搜索此内容.但什么都没做.不知道从哪里开始以及如何开始.
I don't have any idea how to post request to the webpage,get the cookie,store it and use it while sending the above said data by attaching the jSessionId to the url. I've been searching about this from past 2 days. but couldn't get anything to work. No idea where to start and how to.
一个详细的答案就是我要寻找的,因为我也尝试过stackoverflow的答案.还是没有运气
A detailed answer is what I'm looking because I've tried answers from stackoverflow also. Still no luck
到目前为止,我已经设法检索了jsessionid.
I've managed to retrieve the jsessionid so far.
public boolean send() {
String givenDob = dobET.getText().toString();
String givensurname = surnameEt.getText().toString();
String givenCaptcha = captchaET.getText().toString();
String url = "https://mysite/getinfo.html";
try {
URLConnection connection = new URL(url).openConnection();
InputStream response = connection.getInputStream();
List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
Log.d("Link Response", String.valueOf(response));
Log.d("Cookie", String.valueOf(cookies));
String value = cookies.get(0);
if (value.contains("JSESSIONID")) {
int index = value.indexOf("JSESSIONID=");
int endIndex = value.indexOf(";", index);
String sessionID = value.substring(
index + "JSESSIONID=".length(), endIndex);
Log.d("id " ,sessionID);
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
现在如何使用此sessionid并发送edittext数据以检索信息?
Now how do I use this sessionid and send the edittext data to retrieve informaion?
推荐答案
使用Cookimanager
设置整个连接的默认Cookie.我的问题解决了.只需使用URI.builder()
Used Cookimanager
to set default Cookie for the entire connection. And my problem is solved. Just appended the query parameters using URI.builder()
URL strUrl = new URL("https://myurl.com/services/getinfo.html?dateOfBirth="
+ params[0] +
"&surName=" + params[1] +
"&firstName&middleName" +
"&captchaCode=" + params[2]);
这篇关于如何使用jSessionId将多个edittext数据发布到网页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!