我无法使用HTTP CLIENT进行POST,即使我查看浏览器上的所有标头集和参数。
这是我的追踪:
br.com.serasa.captacao.framework.web.http.UnknownHttpResponseHarvestException: POST https://portaldecustas.tjsp.jus.br/portaltjsp/pages/custas/servico/abrir / 400 - Bad Request
at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:483)
at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:448)
at br.com.serasa.captacao.framework.web.page.Page.requestHtml(Page.java:98)
at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPage.enviarFormulario(DareSpPage.java:107)
at br.com.fiveware.dare.sp.emissao.guias.captador.CaptadorDareSP.enviarFormulario(CaptadorDareSP.java:68)
at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPageTest.enviarFormulario(DareSpPageTest.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
这是我的代码:
public void enviarFormulario(DadosContribuinte contribuinte) throws HarvestException
{
LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
params.put("nomeServico", contribuinte.getServico());
params.put("cpfCnpj", contribuinte.getCnpj());
params.put("nome", contribuinte.getNome());
params.put("telefone", contribuinte.getTelefone());
params.put("endereco", contribuinte.getEndereco());
params.put("uf", contribuinte.getUf());
params.put("cidade", contribuinte.getCidade());
HttpPost post = newPostMethod(
URI.create("https://portaldecustas.tjsp.jus.br/portaltjsp/pages/custas/servico/abrir"), 6000);
post.addHeader("Host", "portaldecustas.tjsp.jus.br");
post.addHeader("Accept", "*/*");
post.addHeader("Accept-Language", "en-US,en;q=0.5");
post.addHeader("Accept-Encoding", "gzip, deflate, br");
post.addHeader("Referer", "https://portaldecustas.tjsp.jus.br/portaltjsp/pages/custas/new");
post.addHeader("Content-type", "application/json");
requestHtml(post);
}
这些是请求标头(威盛浏览器):
这些是POST DATA:
{"nomeServico":"estampagem_ou_autenticacao_mecanica","cpfCnpj":"435.248.238-23","nome":"EDERSON DUARTE ITABAIANA JUNIOR","telefone":"(11) 11111-1111","endereco":"teste","uf":"26","cidade":"9422"}