我正在尝试将 woocommerce APi 与 java 一起使用,但它返回 403。当我通过curl 尝试相同的请求时,它工作正常。
已尝试添加/删除请求属性
Java类:
public static void main (String [] args){
String CONSUMER_KEY="consumer_key";
String CONSUMER_SECRET="consumer_secret";
String authString = CONSUMER_KEY + ":" + CONSUMER_SECRET;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
HttpURLConnection conn;
try {
String url ="https://example.com/wp-json/wc/v3/products";
URL url1 = new URL(url);
conn = (HttpURLConnection) url1.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization","Basic "+authStringEnc);
conn.setRequestProperty("header","content-type:application/json");
conn.setRequestProperty("Accept", "*/*");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setInstanceFollowRedirects(false);
InputStream is = conn.getInputStream();
byte[] bytes = IOUtils.toByteArray(is);
String response= GzipUtil.unzip(bytes);
}
catch (Exception e){
}
}
卷曲请求:
卷曲https://example.com/wp-json/wc/v3/products \ -u {consumer_key}:{consumer_secret}
知道如何解决这个问题吗?谢谢
肥皂起泡泡
相关分类