我正在使用polycom设备拨打电话。我需要从Android设备拨打号码。 polycom教程建议我为此目的使用cURL。但是,由于android不支持cURL,我想知道是否有使用HTTP发出请求?
这是我正在使用的cURL命令 -
curl --digest -u abc:xyz -d
"<PolycomIPPhone><URL priority="Critical">SoftKey:Cancel </URL>
</PolycomIPPhone>" --header "Content-Type: application/x-com-polycom-spipx"
http://1.2.3.4/push
其中,abc:xyz是我的用户名/密码
在这种情况下,我无法理解HTTP标头是什么。
编辑:我的polycom手机型号是VVX-550
编辑2:使用以下代码使其正常工作:
public void makeCall(){
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://1.2.3.4/push");
post.setHeader("Content-Type", "application/x-com-polycom-spipx");
if(isAuthRequested){
DigestScheme digestAuth = new DigestScheme();
digestAuth.overrideParamter("algorithm", "MD5");
digestAuth.overrideParamter("realm", "PUSH Authentication");
digestAuth.overrideParamter("nonce", nonce);
digestAuth.overrideParamter("qop", "0");
digestAuth.overrideParamter("nc", "0");
digestAuth.overrideParamter("cnonce", DigestScheme.createCnonce());
Header auth;
try {
auth = digestAuth.authenticate(new
UsernamePasswordCredentials("Username", "password"), post);
post.addHeader(auth);
} catch (AuthenticationException e2) {
e2.printStackTrace();
}
}
HttpEntity entity = null;
try {
entity = new ByteArrayEntity(mXml.getBytes("UTF-8"));
post.setEntity(entity);
HttpResponse response = null;
try {
response = client.execute(post);
} catch (ClientProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if(!isAuthRequested){
Header[] authResp = response.getHeaders("WWW-Authenticate");
for(Header he : authResp){
Log.d("Log","Header: "+he);
String[] firstSplit = he.toString().split(",");
String[] secondSplit = firstSplit[1].split("=");
nonce = secondSplit[1];
nonce = nonce.replaceAll("\"", "");
Log.d("Log","Nonce:"+nonce);
isAuthRequested = true;
makeCall();
}
}
String result = EntityUtils.toString(response.getEntity());
Log.d("Log", "String result: "+result);
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}