let posturl = URL(string: "https://parivahan.gov.in/rcdlstatus/vahan/rcDlHome.xhtml")
var postreq = URLRequest(url: posturl!)
postreq.httpMethod = "POST"
HTTPCookieStorage.shared.setCookies(cookie, for: posturl!, mainDocumentURL: nil)
postreq.setValue("https://parivahan.gov.in/rcdlstatus/?pur_cd=102", forHTTPHeaderField: "Referer")
postreq.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
postreq.setValue("parivahan.gov.in", forHTTPHeaderField: "Host")
postreq.setValue("application/xml, text/xml, */*; q=0.01", forHTTPHeaderField: "Accept")
postreq.setValue("en-US,en;q=0.5", forHTTPHeaderField: "Accept-Language")
postreq.setValue("gzip,deflate, br", forHTTPHeaderField: "accept-encoding")
postreq.setValue("XMLHttpRequest", forHTTPHeaderField: "X-Requested-With")
postreq.setValue("partial/ajax", forHTTPHeaderField: "faces-request")
postreq.setValue("https://parivahan.gov.in", forHTTPHeaderField: "Origin")
let userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140" + "Safari/537.36"
postreq.setValue(userAgent, forHTTPHeaderField: "User-Agent")
let parameter = ["javax.faces.partial.ajax" : "true" ,
"javax.faces.source" : "\(str2)",
"javax.faces.partial.execute" : "@all",
"javax.faces.partial.render" : "form_rcdl:pnl_show form_rcdl:pg_show form_rcdl:rcdl_pnl" ,
"\(str2)" : "\(str2)" ,
"form_rcdl" : "form_rcdl" ,
"form_rcdl:tf_reg_no1" : "\(regno1)" ,
"form_rcdl:tf_reg_no2" : "\(regno2)" ,
"javax.faces.ViewState": "\(vhtype)"]
do{
postreq.httpBody = try JSONSerialization.data(withJSONObject: parameter, options: [])
} catch{
print(error,"error in postreq body")
}
print(str2)
print(regno1,"no1")
print(regno2,"no2")
let posttask = URLSession.shared.dataTask(with: postreq, completionHandler: {(data, response, err) in
if let http = response as? HTTPURLResponse
{
print(http.statusCode)
}
if err == nil
{
let con = String(data: data!, encoding: String.Encoding(rawValue: String.Encoding.ascii.rawValue))as String?
print(con!)
}
})
posttask.resume()