Cosmos db Rest API-未经授权的错误401

时间:2019-02-04 15:05:50

标签: android azure-cosmosdb okhttp3 http-status-code-401

我正在尝试使用REST API使用android获取对db cosmos的get请求! 天蓝色的宇宙数据库有一个特定的标题,但我认为一切正确

但是,当我使用Http REST API时,出现错误Unauthorized 401,您能帮我吗?

expect(add).to.have.been.called.with('cat');

Getwebservices方法

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    n = findViewById(R.id.teste11);
    Button buttonParse = findViewById(R.id.button_parse);
    buttonParse.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                getwebservice();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    client = new OkHttpClient();


}

这些是签名和标头日期的辅助方法

 private void getwebservice() throws Exception {

    String headerDate = getDateString();

    String gen = generateAuthHeader("GET", "docs", "dbs/tempdb/colls/tempcoll/docs/WakefieldFamily",
            headerDate, PRIMARY_KEY);
    final Request request = new Request.Builder()
            .url("https://***.documents.azure.com:443/dbs/***/colls/***/docs/WakefieldFamily")
            .get()
            .addHeader("Accept", "application/json")
            .addHeader("x-ms-version", "2017-02-22")
            .addHeader("Authorization", gen)
            .addHeader("x-ms-date", headerDate)
            .addHeader("cache-control", "no-cache")
            .build();

    okhttp3.Response response = null;
    client.newCall(request).enqueue(new Callback() {
        Headers g = request.headers();
        @Override
        public void onFailure(okhttp3.Call call, IOException e) {
             MainActivity.this.runOnUiThread(new Runnable() {
                 @Override
                 public void run() {
                     String g = "oi";

                 }
             });
        }

        @Override
        public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    n.setText(String.valueOf(response.code()));
                }
            });
        }
    });

    }

我仍在试图弄清楚它是如何工作的。

1 个答案:

答案 0 :(得分:0)

我认为问题是您正在将file_btn.config(command=lambda: os.system('start "" "{}"'.format("C:\Folder1\Folder2\file.docx"))) 变量转换为小写。 stringToSign带有一些大写字母,这些字母在此过程中会转换。