【发布时间】:2018-09-01 07:57:56
【问题描述】:
所以我有这个 javascript 函数,我想将它转换为 java 函数。这是原来的功能:
function mailExistsCheck() {
request({
uri: "https://iag.ksmobile.net/1/cgi/is_exist",
method: "POST",
headers: {
'User-Agent': "FBAndroidSDK.0.0.1", DONE
'Accept-Language': "en_US", DONE
'appid': "135301",
'ver': "3.8.20",
'sid': "17DBB0C2B30D01B590B704501A8AC054",
'sig': "lbOfPDrq0kJNvZX8eYZH9c0Mo7o",
'Host': "iag.ksmobile.net",
'Content-Type': "multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f",
'Transfer-Encoding': "chunked",
'Accept-Encoding': "gzip"
},
body: `--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
Content-Disposition: form-data; name="cmversion"
38201849
--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
Content-Disposition: form-data; name="name"
` + address + `
--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f`
}, (error, response, body) => {
if (error) {
console.error(error);
}
if (body.indexOf("12018") != -1) {
register();
} else {
console.error(body);
console.error("MAIL EXISTENCE CHECK FAILED!");
process.exit(1);
}
});
我正在使用这个库 http://kevinsawicki.github.io/http-request/ 创建 http 请求,到目前为止我有这个:
public static String mailexiste(String address) {
String contentType = HttpRequest.post("https://iag.ksmobile.net/1/cgi/is_exist")
.userAgent("FBAndroidSDK.0.0.1")
.header("Accept-Language", "en_US")
.header("appid", "135301")
.header("ver", "3.8.20")
.header("sid", "17DBB0C2B30D01B590B704501A8AC054")
.header("sig", "lbOfPDrq0kJNvZX8eYZH9c0Mo7o")
.header("Host", "iag.ksmobile.net")
.contentType("multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")
.acceptGzipEncoding()
.contentType(); //Gets response header
return contentType;
我认为我的标题是正确的,我唯一的问题是我的正文部分有问题。我不明白这些请求的大部分,因为我现在才开始学习这个,我想自己做这个程序,但我真的被困在这部分。另外,我如何在java中做if?提前致谢!
【问题讨论】:
-
你最好使用okhttp。看看如何发送form data with okhttp。
-
我会看看@Ahmad ty
-
我认为你可以使用这个method 为body 设置任何字符串
标签: javascript java http post