0
我有使用OAuth後續POST請求和請求主體POST請求失敗由於無效的簽名
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "firstname=martin");
Request request = new Request.Builder()
.url("http://127.0.0.1:8080/api/people/new")
.post(body)
.addHeader("authorization", "OAuth oauth_consumer_key=\"5jyytn5guw84os48scckwkkwkkckwkowcgow04g04oc84kg0c4\",oauth_token=\"qwertzuiop\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1465370390\",oauth_nonce=\"rFED5R\",oauth_version=\"1.0\",oauth_signature=\"aU2zedmum%2BwO3I%2FesAv159nLE8o%3D\"")
.addHeader("cache-control", "no-cache")
.addHeader("content-type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
問題是請求主體(與窗體-urlencoded參數)和所生成的oauth_signature
。沒有身體,我生成的簽名是絕對正確的,並且通話很順利,但是在添加請求主體之後,呼叫失敗,出現401 - unauthorized
我認爲只有oauth頭參數與oauth_signature計算相關?我絕對失去了,並會感謝任何幫助。