任何人都知道为什么我的HTTP帖子请求不起作用?

时间:2017-12-17 16:38:13

标签: java html post

我正在寻找在Java中实现以下HTML代码的一些建议:

<form name="gls" method="post" action="http://datarequester-f01.gls-hungary.com/public/service.php">
    <input type="hidden" name="ctrcode" value="HU" />
    <input type="hidden" name="module" value="cities" />
    <input type="hidden" name="action" value="getToursDB" />
    <input type="hidden" name="data" value="[{'Lastupdate' : null}]" />
    <input type="hidden" name="plaininput" value="1" />
    <input type="hidden" name="resultformat" value="" />
    <input type="submit" value="Send">
</form>

我尝试了很多不同的方法,但响应代码总是400。 这是我的最后一次尝试:

String url=""http://datarequester-f01.gls-hungary.com/public/service.php"";
    CloseableHttpClient client = HttpClients.custom()
            .setHttpProcessor(HttpProcessorBuilder.create().build())
            .build();
    HttpPost post = new HttpPost(url);
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("ctrcode", "HU"));
    urlParameters.add(new BasicNameValuePair("module", "cities"));
    urlParameters.add(new BasicNameValuePair("action", "getToursDB"));
    urlParameters.add(new BasicNameValuePair("data", "[{'Lastupdate' : null}]"));
    urlParameters.add(new BasicNameValuePair("plaininput", "1"));
    urlParameters.add(new BasicNameValuePair("resultformat", ""));
    post.setEntity(new UrlEncodedFormEntity(urlParameters));
    try {
        System.out.println(EntityUtils.toString(post.getEntity()));
    } catch (IOException ex) {
    Logger.getLogger(GLS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParseException ex) {
        Logger.getLogger(GLS.class.getName()).log(Level.SEVERE, null, ex);
    }

    HttpResponse response;
    try {
        response = client.execute(post);
    System.out.println("Response Code : "
            + response.getStatusLine().getStatusCode());
    BufferedReader rd = new BufferedReader(
            new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }
} catch (IOException ex) {
    Logger.getLogger(GLS.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (UnsupportedEncodingException ex) {
    Logger.getLogger(GLS.class.getName()).log(Level.SEVERE, null, ex);
}   

非常感谢任何adive。 谢谢!

0 个答案:

没有答案