【问题标题】:Android Oauth 1.0 Authentication with OkHttp使用 OkHttp 的 Android Oauth 1.0 身份验证
【发布时间】:2023-03-05 13:28:01
【问题描述】:

我正在尝试在 android 中验证 Oauth 1.0。 我向邮递员发送请求并通过邮递员得到响应,这个程序给了我一个 Java 代码,但它不起作用。它返回 401 错误

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url("https://test.com/wp-json/wc/v3/customers? 
oauth_consumer_key=KEY&oauth_token=&oauth_signature_method=HMAC-HA1&oauth_timestamp=1564471240&oauth_nonce=iEo45PESRdt&oauth_version=1.0&oauth_signature=NQR4Xr5OKlb3H+rL0y2PNLdfXpY=")
  .get()
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .addHeader("User-Agent", "PostmanRuntime/7.15.2")
  .addHeader("Accept", "*/*")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Postman-Token", "6fb2e16e-376c-453a-bf30-18ef6c00020c,c14db88a-55dd-4287-a132-8ca441a5e3f0")
  .addHeader("Host", "test.com")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

【问题讨论】:

  • 你得到的回应是什么?它会崩溃吗?你能指定更多吗?
  • 401 错误@Coder123
  • 你 100% 确定你传递了与邮递员相同的标题?
  • 是的,我确定它会返回 {"code":"woocommerce_rest_authentication_error","message":"\u0628\u0631\u0686\u0633\u0628 \u0632\u0645\u0627\u0646 \u0646\ u0627\u0645\u0639\u062a\u0628\u0631\u0627\u0633\u062a.","data":{"status":401}} @Coder123

标签: java android oauth okhttp


【解决方案1】:

似乎邮递员生成的代码不尊重身份验证部分。

转到标题部分并单击“9 hidden”以查看“授权”标题

show hidden

see the auth header

【讨论】:

  • 这不提供解决方案,应作为评论发布
猜你喜欢
  • 1970-01-01
  • 2018-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 1970-01-01
  • 2014-07-23
  • 2015-09-09
相关资源
最近更新 更多