Java 如何阅读对站点的回复

Java 如何阅读对站点的回复,java,Java,我正在通过使用httpclient api以编程方式发送post参数来从站点获取响应,但无法获得所需的响应 这就是我尝试过的: HttpClient httpclient = new DefaultHttpClient(); try { String bin = "--FONT PATH--"; HttpPost httppost = new HttpPost("http://www.freefontconverter.com/index.php

我正在通过使用httpclient api以编程方式发送post参数来从站点获取响应,但无法获得所需的响应

这就是我尝试过的:

HttpClient httpclient = new DefaultHttpClient();

    try
    {
        String bin = "--FONT PATH--";
        HttpPost httppost = new HttpPost("http://www.freefontconverter.com/index.php");

        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        File fileToUpload = new File(bin);
        FileBody fileBody = new FileBody(fileToUpload,"application/octet-stream");
        entity.addPart("fontFile", fileBody);
        entity.addPart("outputFormat", new StringBody("ttf"));
        entity.addPart("submit", new StringBody("Convert"));

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        if (resEntity != null)
        {
                 //Want a ttf response as attachment file here------------------
        }
        EntityUtils.consume(resEntity);
    }
    finally
    {
        httpclient.getConnectionManager().shutdown();
    }

是否有什么我忘记编码的东西或其他选择?

你说的“无法获得所需的响应”是什么意思?确切的错误是什么(如果有的话)?你得到了什么回报?您应该尝试使用fiddler来检查http响应。为什么不使用catch(异常e)进行调试呢?我在这里得到了一个text/html响应(200),但实际上表单给出了一个ttf文件。