0

我正在努力通过使用 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();
    }

有什么我忘记编码的东西或任何替代方法吗?

4

0 回答 0