Skip to Content
0

Android Volley calling oData using Request.POST giving 403 Error

Mar 01 at 02:36 PM

140

avatar image
Former Member

Hi Experts

I am calling SAP's oData Service using Volley API from Android and getting HTTP 403 Error for the Request.POST. But for the Request.GET for another Service program is working fine. May I know if there is any issue with my code calling oData Service.

Iam passing MYSAPSSO2 token and CSRF Token obtained from my first request call. But getting Authentication error. Any idea what is missing here?

Same oData POST service using JQUERY/SAPUI5 is working fine without any issues.

try {
            /** json object parameter**/
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("SO", so);
            jsonObject.put("STATUS", status);
            jsonObject.put("NET_VALUE", amount);
            Log.i("XXXX", thisMethod+"jsonObject params"+ jsonObject.toString() + "");
            JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject jsonRespObj) {
                    Log.i("XXXX", thisMethod+"Response from notification service: " + jsonRespObj.toString());
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Log.i("XXXXX", thisMethod+"Error Response: " + volleyError);
                    volleyError.printStackTrace();
                }
            }
            ) {
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    if (mysapsso2 != null) {
                        Log.i("XXX", thisMethod+"MYSAPSSO2 is : " + TokenHandler.getMYSAPSSO2Token());
                        Log.i("XXXX", thisMethod+"X-CSRF-Token is : " + TokenHandler.getCSRFToken());
                        params.put("Cookie", ServiceClass.mysapsso2);
                        params.put("X-CSRF-Token", TokenHandler.getCSRFToken());
                        params.put("contentType", "application/json");
                    }
                    return params;
                }
            };
            queue.add(jsonObjectRequest);
        } catch (JSONException e) {
            Log.e("XXX", thisMethod+"There was an error => " + e.getMessage());
            e.printStackTrace();
        }
        catch (Exception e) {
            Log.e("XXXX", thisMethod+"There was an error => " + e.getMessage());
            e.printStackTrace();
        }
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Bartosz Jarkowski Mar 01 at 03:14 PM
0

Do you connect to systems based on Netweaver? Can you check if the respective ICF node is active for OData?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 01 at 03:19 PM
0

I think you mean the odata service is active or not in SICF under oData node? yes it is active. the same service is working fine when tired with jQuery.ajax or ODATAModel in SAPUI5 , but I want to hit the service from Volley API in Android for some other purpose and failing.

Share
10 |10000 characters needed characters left characters exceeded