如何使用 OkHttp 为下行频道流正确创建 http 请求 header

How to properly create an http request header for a downchannel stream using OkHttp

我们尝试按照此处的说明使用来自此网站的 GET 请求建立下行通道流:https://developer.amazon.com/en-US/docs/alexa/alexa-voice-service/manage-http2-connection.html#Maintaining%20an%20HTTP/2%20Connection

代码如下:

/* The user is signed in */
Log.d( "accessToken", "authorizeResult.toString(): " + authorizeResult.toString());
Log.d("accessToken", "accessToken: " + accessToken);
 
// OkHttpClient: establish a downchannel stream
OkHttpClient httpClient = new OkHttpClient();
OkHttpClient downChannelClient = httpClient.newBuilder() //httpClient Variable? Declare at beginning
        .connectTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .readTimeout(30, TimeUnit.SECONDS)//.connectionPool(connectionPool)
        .build();
 
// OKHttp header creation.
final Request request = new Request.Builder()
        .url("https://alexa.na.gateway.devices.a2z.com")//endpoint url
        .get()
        .addHeader("method", "GET")
        .addHeader("scheme", "https")
        .addHeader("path", "/" + AVS_API_VERSION + "/directives")
        .addHeader("authorization", "Bearer " + accessToken)
        // A boundary term is required in the header of each event sent to AVS
        .addHeader("content-type", "multipart/form-data; boundary=" + BOUNDARY_TERM)
        .build();
 
Log.d("Request_header", request.toString());
 
Call currentCall = downChannelClient.newCall(request);
 
Response response = null;
try {
    response = currentCall.execute();
}
catch (IOException e) {
    Log.d("Response error", e.getMessage());
}
 
if (response != null && response.body() != null) {
    Log.d("Response_success", String.valueOf(response.isSuccessful()));
    Log.d("Response_str", response.toString());
}

但我们不断收到 404 代码和错误响应成功。

D/Request_header: Request{method=GET, url=https://alexa.na.gateway.devices.a2z.com/, headers=[method:GET, path:/v20160207/directives, authorization:Bearer <access_token_censored>, content-type:multipart/form-data; boundary=------------------------qM9tn4VZyj]}
D/Response_success: false
D/Response_str: Response{protocol=h2, code=404, message=, url=https://alexa.na.gateway.devices.a2z.com/}

我们不确定我们的请求是否设置正确。

我希望路径是 URL

的一部分
final Request request = new Request.Builder()
        .url("https://alexa.na.gateway.devices.a2z.com/v20160207/directives")//endpoint url
        .addHeader("authorization", "Bearer " + accessToken)
        // A boundary term is required in the header of each event sent to AVS
        .addHeader("content-type", "multipart/form-data; boundary=" + BOUNDARY_TERM)
        .build();