cancel
Showing results for 
Search instead for 
Did you mean: 

Android Volley calling oData using Request.POST giving 403 Error

03-01-2018 3:36 PM
3105 views 2 comments
0 Likes
SAP Managed Tags
Subscribe

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();
        }
0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Likes

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.

BJarkowski
Active Contributor
0 Likes

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