0

为了向 a 发送消息Cisco VoIP Phone,我使用Apache HttpClient

HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(body, ContentType.TEXT_XML));
httpPost.addHeader(new BasicScheme().authenticate(usernamePasswordCredentials, httpPost, null));

XML消息看起来像这样

String body = 
    """
    XML=
    <CiscoIPPhoneText>
        <Title>...</Title>
        <Prompt>...</Prompt>
        <Text>...</Text>
    </CiscoIPPhoneText>            
    """;

URL使用的是地址IP类似

String url = "https://<ip-adress>/CGI/Execute";

Wenn 执行POST请求

HttpResponse response = closeableHttpClient.execute(httpPost);

我收到状态码400

<CiscoIPPhoneError Number="1"></CiscoIPPhoneError>

我不知道这意味着什么以及POST请求有什么问题。

身份验证接缝已经成功,因为如果我删除该部分,httpPost.addHeader(new BasicScheme()...那么我得到401.

4

1 回答 1

0

HTTP POST 的内容应该是 application/x-www-form-urlencoded 格式,因此指定正确的内容标头并编码 XML=[data],如下所示:

POST /CGI/Execute HTTP/1.1
Host: 10.99.58.26
Authorization: Basic ZHN0YXVkdDpwYXNzd29yZA==
User-Agent: curl/7.74.0
Accept: */*
Content-Length: 427
Content-Type: application/x-www-form-urlencoded

XML=%3CCiscoIPPhoneText%3E%0A%20%20%20%20%3CText%3EHello%20World%3C%2FText%3E%0A%20%20%20%20%3CSoftKeyItem%3E%0A%20%20%20%20%20%20%20%20%3CName%3ECustom%3C%2FName%3E%0A%20%20%20%20%20%20%20%20%3CURL%3ENotify%3Ahttp%3A10.24.152.227%3A8080%3Atestpath%3AZHN0YXVkdDpwYXNzd29yZA%3D%3D%3Atestdata%3C%2FURL%3E%0A%20%20%20%20%20%20%20%20%3CPosition%3E1%3C%2FPosition%3E%0A%20%20%20%20%3C%2FSoftKeyItem%3E%0A%3C%2FCiscoIPPhoneText%3E%0A

(交叉发布于https://community.cisco.com/t5/other-collaboration-subjects/tesxt-message-to-voip-phone-ciscoripphoneerror-1/mp/4435874

于 2021-07-23T19:56:35.177 回答