我正在努力通过使用httpclient api以编程方式发送帖子参数但无法获得所需的响应来从站点获取响应。
这就是我的尝试:
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();
}
有什么东西我会忘记编码或替代它吗?