创建文件Rest API会抛出403,但是GET可以正常工作 [英] Create file Rest API throws 403 however GET works fine

查看:81
本文介绍了创建文件Rest API会抛出403,但是GET可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用rest api创建文件.但我继续得到403.用同样的方法,我可以获取文件,但是在PUT的情况下,我可以继续获取文件

Hi, I am trying to create file using rest api. but I keep on getting 403 . With the same way I am able to get file but in case of PUT I keep on getting

响应消息:服务器未能验证请求.请确保正确构成Authorization标头的值(包括签名).
响应码:403

Response message : Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Response code : 403

我正在用java 

I am creating string to sign like this in java 

字符串 stringToSign = "PUT \ n" + "\ n" //内容编码

String stringToSign = "PUT\n" + "\n" // content encoding

+ "\ n" //内容语言

+ "\n" // content language

+ " 0" //内容长度

+ "0" // content length

+ "\ n" //内容md5

+ "\n" // content md5

+ "\ n" //内容类型

+ "\n" // content type

+ "\ n" //日期

+ "\ n" //(如果自此以来已被修改)

+ "\n" // if modified since

+ "\ n" //如果匹配

+ "\n" // if match

+ "\ n" //如果不匹配

+ "\n" // if none match

+ "\ n" //(如果自此以来未修改)

+ "\n" // if unmodified since

+ "\ n" //范围

+ " x-ms-content-length:1024 \ n"

+ "x-ms-content-length:1024\n"

+ " x-ms-date:" + date + " \ nx-ms-type:file \ n"

+ "x-ms-date:" + date + "\nx-ms-type: file\n"

+ " x-ms-version:2015-02-21 \ n" //标头

+ "x-ms-version:2015-02-21\n" // headers

+ "/" + 帐户   + request .getURL().getPath(); //资源

+ "/" + account  + request.getURL().getPath(); // resources

和设置标题

请求 .setRequestMethod("PUT"; );

request.setRequestMethod("PUT");

request .setRequestProperty("Content-Length" "0" );

request.setRequestProperty("Content-Length", "0");

request .setRequestProperty("x-ms-content-length" 跨度>, "1024" );

request.setRequestProperty("x-ms-content-length", "1024");

request .setRequestProperty("x-ms-date"; date );

request.setRequestProperty("x-ms-date", date);

request .setRequestProperty("x-ms-type" 文件" );

request.setRequestProperty("x-ms-type", "file");

request .setRequestProperty("x-ms-version" "2015-02-21" );

request.setRequestProperty("x-ms-version", "2015-02-21");

request .setRequestProperty("Authorization" auth );

request.setRequestProperty("Authorization", auth);

还将身份验证创建为

私有 静态字符串getAuthenticationString(String stringToSign )抛出 异常 {

private static String getAuthenticationString(String stringToSign) throws Exception {

Mac mac = Mac.getInstance("HmacSHA256" ) ;

Mac mac = Mac.getInstance("HmacSHA256");

mac .init( new SecretKeySpec(Base64.decode( key ), "HmacSHA256" ));

mac.init(new SecretKeySpec(Base64.decode(key), "HmacSHA256"));

字符串 authKey = String (Base64.encode( mac .doFinal( stringToSign .getBytes(" UTF-8" ))) ));

String authKey = new String(Base64.encode(mac.doFinal(stringToSign.getBytes("UTF-8"))));

字符串 auth = " SharedKey" + 帐户 + ":" + authKey ;

String auth = "SharedKey " + account + ":" + authKey;

返回 auth ;

}

请帮助我解决此错误.

推荐答案

你好,

请确保时间设置正确(时区),或者本地计算机上的系统时钟没有关闭.

Please make sure that the time settings are correct (timezone) or if the system clock isn't turned off on your local computer. 

https://docs.microsoft.com/zh-cn/previous-versions/windows/it-pro/windows-server-2003/cc738995(v = ws.10)

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc738995(v=ws.10)

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click Here


这篇关于创建文件Rest API会抛出403,但是GET可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆