所以我有这个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?提前谢谢!
答案 0 :(得分:1)
Host
标题,它将自动添加到库中.part(String name,String value)
在多部分中添加部件:你应该得到类似的东西:
.contentType("multipart/form-data")
.part("cmversion", "38201849")
.part(name, address)
答案 1 :(得分:0)
if()在Java中与在JavaScript中几乎相同。