apache-httpclient-4.xciscocisco-axl

Apache HttpClient, Cisco VoIP Phone - POST CGI Execute CiscoIpPhoneError 1


For sending a message to a Cisco VoIP Phone, I use Apache HttpClient:

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

The XML message looks like this

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

The URL used is with IP adress like

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

Wenn executing the POST request

HttpResponse response = closeableHttpClient.execute(httpPost);

I recieve status code 400 and

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

I don't know what that means and what the problem is with the POST request.

The authentication seams to have been successful, because if I remove the part httpPost.addHeader(new BasicScheme()... then I get 401.


Solution

  • The content of the HTTP POST should be in application/x-www-form-urlencoded format, so specifying the right content header and encoding the XML=[data], something like:

    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
    

    (Crossposted at https://community.cisco.com/t5/other-collaboration-subjects/tesxt-message-to-voip-phone-ciscoripphoneerror-1/m-p/4435874)