通过JAVA客户端通过XSOData调用REST端点时的POST方法的HTTP 403

2020-09-04 13:56发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


专家您好,

******

我的GET方法成功返回 200 ,但是当我将令牌解析为POST方法时,我得到 HTTP 403 ,而在 JS 中 可以成功

任何输入/建议都是有帮助的

url =新URL(" https://******* 试用版。 hanatrial.ondemand.com :443/sap/hana/xs/admin/appMyOdata/services.xsodata/myODataURL5");
HttpURLConnection conn1 =(HttpURLConnection)url.openConnection();

字符串token1 = null;
conn1.setRequestMethod(" POST");
//conn1.setRequestProperty("access-control-allow-credentials","true");
conn1.setRequestProperty(" Username"," MAMID");
conn1.setRequestProperty(" Password"," ******");


conn1.setRequestProperty(" Access-Control-Allow-Origin "," *");
//conn1.setRequestProperty("USER_AGENT"," Mozilla/5.0 Firefox/26.0");
conn1.setRequestProperty(" User-Agent"," Java客户端"); < br> conn1.setRequestProperty(" Content-Type"," application/x-www-form-urlencoded");
conn1.setRequestProperty(" Authorization"," Basic TUFNSUQ6QmxyMTIzNDUq");
//conn1.setRequestProperty ("内容类型","应用程序/json");
//conn1.setRequestProperty("Content-Type"," application/json; charset = UTF-8");
conn1.setRequestProperty(" x-csrf-token",令牌);
< br> conn1.setDoInput(true);
conn1.setDoOutput(true);

字符串输入=" {\" RecordNo \":21,\" Release \":\" 1905 \", \" AppID \":\" F777 \",\" AppType \":\" Tranactional \",\" Complexity \":\" Simple \",\" Url \":\\ https://localhost \ ",\" StepName \":\" Step2 \"}";
OutputStream os = conn1.getOutputStream();
os.write(input.getBytes());
os.flush() ;

if(conn1.getResponseCode()!= HttpURLConnection.HTTP_CREATED){
throw new RuntimeException(" Failed:HTTP error code:" +
conn1.getResponseCode());
}

br = new BufferedReader(new InputStreamReader(
(conn1.getInputStream())));


System.out.println("服务器输出... 。\ n");
while((output = br.readLine())!= null){
System.out.println(output);
}

conn1.disconnect ();

}捕获(MalformedURLException e){

e.printStackTrace();

} catch(IOException e){

e.printStackTrace();

}

}

谢谢

Dilip

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


专家您好,

******

我的GET方法成功返回 200 ,但是当我将令牌解析为POST方法时,我得到 HTTP 403 ,而在 JS 中 可以成功

任何输入/建议都是有帮助的

url =新URL(" https://******* 试用版。 hanatrial.ondemand.com :443/sap/hana/xs/admin/appMyOdata/services.xsodata/myODataURL5");
HttpURLConnection conn1 =(HttpURLConnection)url.openConnection();

字符串token1 = null;
conn1.setRequestMethod(" POST");
//conn1.setRequestProperty("access-control-allow-credentials","true");
conn1.setRequestProperty(" Username"," MAMID");
conn1.setRequestProperty(" Password"," ******");


conn1.setRequestProperty(" Access-Control-Allow-Origin "," *");
//conn1.setRequestProperty("USER_AGENT"," Mozilla/5.0 Firefox/26.0");
conn1.setRequestProperty(" User-Agent"," Java客户端"); < br> conn1.setRequestProperty(" Content-Type"," application/x-www-form-urlencoded");
conn1.setRequestProperty(" Authorization"," Basic TUFNSUQ6QmxyMTIzNDUq");
//conn1.setRequestProperty ("内容类型","应用程序/json");
//conn1.setRequestProperty("Content-Type"," application/json; charset = UTF-8");
conn1.setRequestProperty(" x-csrf-token",令牌);
< br> conn1.setDoInput(true);
conn1.setDoOutput(true);

字符串输入=" {\" RecordNo \":21,\" Release \":\" 1905 \", \" AppID \":\" F777 \",\" AppType \":\" Tranactional \",\" Complexity \":\" Simple \",\" Url \":\\ https://localhost \ ",\" StepName \":\" Step2 \"}";
OutputStream os = conn1.getOutputStream();
os.write(input.getBytes());
os.flush() ;

if(conn1.getResponseCode()!= HttpURLConnection.HTTP_CREATED){
throw new RuntimeException(" Failed:HTTP error code:" +
conn1.getResponseCode());
}

br = new BufferedReader(new InputStreamReader(
(conn1.getInputStream())));


System.out.println("服务器输出... 。\ n");
while((output = br.readLine())!= null){
System.out.println(output);
}

conn1.disconnect ();

}捕获(MalformedURLException e){

e.printStackTrace();

} catch(IOException e){

e.printStackTrace();

}

}

谢谢

Dilip

付费偷看设置
发送
1条回答
渐行渐远_HoldOn
1楼 · 2020-09-04 14:53.采纳回答

你好

是的,由于Naveen V

,发现解决方案 cookie 必须设置有效负载

谢谢

Dilip

一周热门 更多>