cancel
Showing results for 
Search instead for 
Did you mean: 

SMP 3.0 SP 07 - Issue while post operation in iOS

Former Member
0 Kudos

Hi ,

We are on SMP 3.0 sp07 and are building an application that consumes oData services. We are able to retrieve data , but facing issues while create / post operation.

Below is the code for post operation :-

        [RequestBuilder setRequestType:HTTPRequestType];

       

        [RequestBuilder enableXCSRF:YES];

       

        id<Requesting> postRequest = [RequestBuilder requestWithURL:[[NSURL alloc] initWithString:self.endpointURL]];

       

        [postRequest setRequestMethod:@"POST"];

       

        [postRequest addRequestHeader:@"aaaaa" value:@"xxxx"]; // Header value is passed here

       

        [postRequest setPostBody:postData]; //  post data is json converted from a nsdictionary

       

        [postRequest setDelegate:self];

       

        [postRequest startAsynchronous];


Operation works fine and is tested on rest client where we need to pass one request header and other data in payload.


I have passed the necessary headers and payload through my code as well. But the operation fails saying "Error 405 - Method not allowed"


What am i missing ?


Any inputs would be appreciated.


Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Amit,

I guess self.endpointURL in your code refers to the service document URL. If you are posting to a particular collection, the URL for posting should be the URL of that particular collection.

eg:

   id<Requesting> odp_postRequest = [RequestBuilder requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@SalesOrders", endPoint_URL];]]


Regards,

Dhani

Former Member
0 Kudos

Hi Dhani,

The endpoint URL is referring to the desired collection. I checked that in debug mode and is constructed properly till the collection.

Thanks,

Amit

Former Member
0 Kudos

Hi Amit,

Can you plese share the screenshots of the Restclient request and response?

Are you passing X-CSRF Token while posting?

In RestClient, are you passing data in XML format or json format?

Regards,

Dhani

Former Member
0 Kudos

Hi Dhani,

I am not passing X-CSRF token from rest client while posting. Data is passed in json format.

Thanks,

Amit

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Can you please provide a screenshot how you are trying with POST operation in REST client?

X-CSRF-TOKEN is required for POST, PUT, delete operations.

Regards,

JK

Former Member
0 Kudos

Below is the screenshot from rest client. X-CSRF token is generated by another middle tier team who build web services connecting to backend.

Another update , i made some changes to the front end code and i am getting "Error code 415 - unsupported media type" in the logs.

Any thoughts ?

Thanks,

Amit

Former Member
0 Kudos

Screenshot is attached in below comments.

Former Member
0 Kudos

Hi Amit,

Add the Content-Type header value  also in the request. I guess that  will remove this unsupported media type error.

Regards,

Dhani

Answers (0)