1
What I got so far is this:
package br.com.crawler;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class Crawler {
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) throws Exception {
Crawler http = new Crawler();
System.out.println("\nTesting 1 - Enviar request via POST");
http.sendPost();
}
// HTTP POST request
private void sendPost() throws Exception {
String url = "https://www.nfp.fazenda.sp.gov.br/login.aspx";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = "__EVENTVALIDATION=&"
+ "__EVENTARGUMENT=&"
+ "__VIEWSTATE=/wEPDwUKMTMwMTM2MTg2MA9kFgJmD2QWAgIBD2QWCgIDDxYCHgVjbGFzcwUYYmFycmFBY2Vzc2liaWxpZGFkZUxvZ2luFgQCAQ8WAh4HVmlzaWJsZWhkAgMPFgIfAWdkAgQPFgIfAWhkAgYPDxYCHgRUZXh0BRROb3RhIEZpc2NhbCBQYXVsaXN0YWRkAggPFgIfAWhkAgoPZBYCZg9kFgJmD2QWBAIJDw8WAh8BZ2RkAg8PZBYCAgUPZBYCAgEPZBYCAgEPDxYEHghUYWJJbmRleAENAB4JTWF4TGVuZ3RoAgRkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WCAUtY3RsMDAkQ29udGV1ZG9QYWdpbmEkTG9naW4xJHJkQnRuQ29udHJpYnVpbnRlBTBjdGwwMCRDb250ZXVkb1BhZ2luYSRMb2dpbjEkcmRCdG5OYW9Db250cmlidWludGUFLWN0bDAwJENvbnRldWRvUGFnaW5hJExvZ2luMSRyZEJ0bkNvbnRhYmlsaXN0YQUrY3RsMDAkQ29udGV1ZG9QYWdpbmEkTG9naW4xJHJkQnRuRmF6ZW5kYXJpbwUnY3RsMDAkQ29udGV1ZG9QYWdpbmEkTG9naW4xJHJkQnRuUHJvY29uBTZjdGwwMCRDb250ZXVkb1BhZ2luYSRMb2dpbjEkcmRCdG5BZHZvZ2Fkb1JlcHJlc2VudGFudGUFL2N0bDAwJENvbnRldWRvUGFnaW5hJExvZ2luMSRpbWdCdG5BY2Vzc29DZXJ0Q1BGBTBjdGwwMCRDb250ZXVkb1BhZ2luYSRMb2dpbjEkaW1nQnRuQWNlc3NvQ2VydENOUEo=&"
+ "ctl00$ConteudoPagina$Login1$rblTipo=rdBtnNaoContribuinte&"
+ "ConteudoPagina$Login1$UserName="+user+"&"
+ "ctl00$ConteudoPagina$Login1$Password="+password;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("Enviando 'POST' request para a URL : " + url);
System.out.println("Parâmetros parameters : " + urlParameters);
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
}
My question is I don’t know what parameters to pass.
In case the parameters you do not know what would be in the
String urlParameters = "param1=valor1¶m2=valor2";
?– Victor Stafusa
so, I put this as an example only, but it should have something like login and password and a few others
– roque
I’m passing these parameters ---
ctl00$ConteudoPagina$Login1$rblTipo=rdBtnContribuinte&ctl00$ConteudoPagina$Login1$rblTipo=rdBtnNaoContribuinte$ConteudoPagina$Login1$rblTipo=rdBtnContabilista$ConteudoPagina$Login1$rblTipo=rdBtnFazendario$ConteudoPagina$Login1$rblTipo=rdBtnProcon$ConteudoPagina$Login1$rblTipo=rdBtnAdvogadoRepresentante$ctl00$ConteudoPagina$Login1$UserName=valor2$ctl00$ConteudoPagina$Login1$Password=valor2
– roque
but it seems that being radio button need to command which of them was checked, eh in that I’m locking
– roque
Could you edit the question to put these details? It’s easier to understand than to see in the comments.
– Victor Stafusa
I edited, that user and passward I am going to receive from the user.
– roque
It seems to me that several are missing
&
in its parameters.– Victor Stafusa
I got what you said, executed but still not accepted the parameters
– roque
Lacked a
&
after theuser
.– Victor Stafusa
Once the name
ctl00$ConteudoPagina$Login1$rblTipo
makes it seem that this is a radio button, I think you should just put one of them, and not all.– Victor Stafusa
so, this radio button question that I’m not knowing how to pass, I researched some things seems to have to pass which one of them was checked but tried a few ways and it didn’t work, maybe if I pass only one of them works, I will test vlw
– roque
I added some inputs that were like Hidden in the parameters, but it didn’t work for him to send me to a screen saying that a request failed
– roque
If you add one
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
something changes?– Victor Stafusa
I added, but nothing changed sent me to this page https://www.nfp.fazenda.sp.gov.br/Erro.aspx
– roque