Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;格式错误的请求”;在Twilio Android客户端中进行呼叫时出错_Android_Request_Voip_Twilio_Malformed - Fatal编程技术网

&引用;格式错误的请求”;在Twilio Android客户端中进行呼叫时出错

&引用;格式错误的请求”;在Twilio Android客户端中进行呼叫时出错,android,request,voip,twilio,malformed,Android,Request,Voip,Twilio,Malformed,我正在尝试将Twilio客户端集成到一个更大的应用程序中。在我调用device.connect(参数,connectionListener)之前,一切似乎都正常。我得到了31100通用格式错误请求错误,就是这样 在同一台设备上,使用相同的Twilio帐户和相同的Twilio应用程序,Twilio Android SDK(MonkeyPhone)提供的示例代码可以完美地工作 我找不到更多关于错误含义或可能原因的详细信息。虽然我假设我发送的是无效数据,但我不知道这怎么可能。功能令牌是正常的,我已经对

我正在尝试将Twilio客户端集成到一个更大的应用程序中。在我调用
device.connect(参数,connectionListener)
之前,一切似乎都正常。我得到了
31100通用格式错误请求
错误,就是这样

在同一台设备上,使用相同的Twilio帐户和相同的Twilio应用程序,Twilio Android SDK(MonkeyPhone)提供的示例代码可以完美地工作

我找不到更多关于错误含义或可能原因的详细信息。虽然我假设我发送的是无效数据,但我不知道这怎么可能。功能令牌是正常的,我已经对照MonkeyPhone示例应用程序中生成的令牌进行了验证。创建
设备
工作正常,没有错误。即使在
connect()
方法中没有发送任何参数,也会引发错误。调用了
ConnectionListener
onConnecting()
方法,但随后调用了
onDisconnected(Connection-inConnection,int-inErrorCode,String-inErrorMessage)
,请求格式错误

Voice TwiML的代码运行良好,它只是一个简单的PHP脚本,生成了最简单的
动词:

<Response>
    <Dial>someone</Dial>
</Response>

多谢各位

我解决了这个问题。显然,我必须使用UTF-8编码从服务器读取InputStream(即使令牌中没有特殊字符)


您是否在后台服务中为来电实现了twilio代码?对不起,已经很久了,我不记得了。
public class MonkeyPhone implements Twilio.InitListener, DeviceListener {
private static final String TAG = "MonkeyPhone";

private Context context;
private Device device;
private Connection connection;

public MonkeyPhone(Context context) {
    this.context = context;
    Twilio.initialize(context, this /* Twilio.InitListener */);
}

@Override
/* Twilio.InitListener method */
public void onInitialized() {
    Log.d(TAG, "Twilio SDK is ready");

    // the Emulator has a somewhat unique "product" name
    String clientName = "doug";

    HttpGet get = new HttpGet("http://teamphoenix.zzl.org/capability.php?ClientName=" + clientName);

    JsonAsyncRequestWithError asyncRequestWithError = new JsonAsyncRequestWithError(context, "test", new AsyncRequestWithErrorListener() {

        @Override
        public void onResult(AsyncRequestResponse response, Object destination) {
            createDevice(response.getMessage());
        }

        @Override
        public void onErrorResult(AsyncRequestResponse response, Object destination) {

        }
    });

    asyncRequestWithError.execute(get);

}

public void createDevice(String token) {
    try {
        device = Twilio.createDevice(token, this /* DeviceListener */);

        Intent intent = new Intent(context, SpringshotPhoneActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        device.setIncomingIntent(pendingIntent);

    } catch (Exception e) {
        Log.e(TAG, "", e);
    }
}

@Override
/* Twilio.InitListener method */
public void onError(Exception e) {
    Log.e(TAG, "Twilio SDK couldn't start: " + e.getLocalizedMessage());
}

@Override
/* DeviceListener method */
public void onStartListening(Device inDevice) {
    Log.i(TAG, "Device is now listening for incoming connections");
}

@Override
/* DeviceListener method */
public void onStopListening(Device inDevice) {
    Log.i(TAG, "Device is no longer listening for incoming connections");
}

@Override
/* DeviceListener method */
public void onStopListening(Device inDevice, int inErrorCode, String inErrorMessage) {
    Log.i(TAG, "Device is no longer listening for incoming connections due to error " + inErrorCode + ": " + inErrorMessage);
}

@Override
/* DeviceListener method */
public boolean receivePresenceEvents(Device inDevice) {
    return false; // indicate we don't care about presence events
}

@Override
/* DeviceListener method */
public void onPresenceChanged(Device inDevice, PresenceEvent inPresenceEvent) {
}

public void connect(String phoneNumber) {
    Map<String, String> parameters = new HashMap<String, String>(1);
    parameters.put("PhoneNumber", phoneNumber);
/// ---------------- THIS IS THE CALL THAT FAILS ------------------------------------//
    connection = device.connect(parameters, null /* ConnectionListener */);
    if (connection == null)
        Log.w(TAG, "Failed to create new connection");
}

public void disconnect() {
    if (connection != null) {
        connection.disconnect();
        connection = null;
    }
}

public void handleIncomingConnection(Device inDevice, Connection inConnection) {
    Log.i(TAG, "Device received incoming connection");
    if (connection != null)
        connection.disconnect();
    connection = inConnection;
    connection.accept();
}

@Override
protected void finalize() {
    if (connection != null)
        connection.disconnect();
    if (device != null)
        device.release();
}
}
    char[] buf = new char[1024];
    InputStream is = response.getEntity().getContent();
    StringBuilder out = new StringBuilder();

    Reader in = new InputStreamReader(is, "UTF-8");

    int bin;
    while ((bin = in.read(buf, 0, buf.length)) >= 0) {
        out.append(buf, 0, bin);
    }

    return out.toString();