如何在URLConnection

时间:2015-08-07 08:12:59

标签: java curl

我尝试将Nuance Dragon API用于我的Java应用程序。 由于我对cURL一无所知,因此我将-k , -v--data-binary参数设置为URLConnection - 对象时遇到了问题。

cURL请求:

curl "https://dictation.nuancemobility.net:443/NMDPAsrCmdServlet/dictation?appId=[INSERT YOUR APP ID]&appKey=[INSERT YOUR 128-BYTE STRING APP KEY]&id=C4461956B60B" 
-H "Content-Type: audio/x-wav;codec=pcm;bit=16;rate=8000" 
-H "Accept-Language: ENUS" 
-H "Transfer-Encoding: chunked" 
-H "Accept: application/xml" 
-H "Accept-Topic: Dictation" 
-k --data-binary @audio.wav  -v

我目前的代码:

 URLConnection connection = new URL(url).openConnection();
 connection.setDoOutput(true); 
 connection.setRequestProperty("Accept-Charset", "ENUS");
 connection.setRequestProperty("Content-Type", "audio/x-wav;codec=pcm;bit=16;rate=8000");
 connection.setRequestProperty("Transfer-Encoding", "chunked");
 connection.setRequestProperty("Accept", "application/xml");
 connection.setRequestProperty("Accept-Topic", "Dictation");

这个问题有更简单的解决方案吗?也许是java-lib?

感谢。

0 个答案:

没有答案