Skip to Content
author's profile photo Former Member
Former Member

OData POST request returning 403 forbidden

Hi All,

I am trying to make a POST request from windows mobile 6.5 through SUP; I have included the headers X-CSRF-Token and X-SUP-APPCID. Please help me to correct the error in my code.

HttpWebRequest request =

(HttpWebRequest)HttpWebRequest.Create(url);

request.Credentials = cache;

request.Method = "POST";

request.ContentType = "application/atom+xml";

request.Accept = "application/xml,application/atom+xml";

request.AllowWriteStreamBuffering = true;

request.Headers.Add("X-SUP-SC", "Security1");

request.Headers.Add("X-CSRF-Token", XCSRFToken);

request.Headers.Add("X-SUP-APPCID", ApplicationConnectionID);

request.Headers.Add("X-SUP-URLREWRITE-ENABLED", "False");

request.Headers.Add("Set-Cookie", strCookie);

byte[] bytes = Encoding.UTF8.GetBytes(postData);

request.ContentLength = bytes.Length;

using (Stream putStream = request.GetRequestStream())

{

putStream.Write(bytes, 0, bytes.Length);

putStream.Close();

}

` WebResponse response = request.GetResponse();

Add comment
10|10000 characters needed characters exceeded

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 15, 2013 at 08:58 AM

    I resolved the issue by formatting the cookie which is returning from the response.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 25, 2013 at 04:49 AM

    What is the error you are getting?

    Are you passing the token and cookie correctly ?

    - Midhun VP

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi ,

      Thanks for your response. Stack Trace is given below.

      Before post request I send GET request and stored the XCSRF token and cookie as below

      strXCSRFToken = response.Headers["X-CSRF-Token"];

      strCookie =response.Headers["Set-Cookie"];

      {System.Net.WebException: The remote server returned an error: (403) Forbidden.

      at System.Net.HttpWebRequest.finishGetResponse()

      at System.Net.HttpWebRequest.GetResponse()

      at WindowMobile3._5OData.Form1.PostBankDetail()

      at WindowMobile3._5OData.Form1.Form1_Load(Object sender, EventArgs e)

      at System.Windows.Forms.Form.OnLoad(EventArgs e)

      at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)

      at System.Windows.Forms.Control.set_Visible(Boolean value)

      at System.Windows.Forms.Application.Run(Form fm)

      at WindowMobile3._5OData.Program.Main()

      }

  • Posted on Jun 25, 2013 at 05:25 AM

    I believe that you are requesting a bad url.

    Please try the POST method in firefox restclient and make sure that the POST is working.

    - Midhun VP

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 25, 2013 at 06:35 PM

    Try removing these two lines from the request:

    request.ContentType = "application/atom+xml";

    request.Accept = "application/xml,application/atom+xml";

    If I remember on the JavaScript side for WM 6.5, above two lines caused issues. I would imagine the same code is being used when you try to do the same thing from C#.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 12, 2013 at 01:19 PM

    Hi,

    Try Adding this additional header.

    X-Requested-With : XMLHttpRequest

    and check if it works.

    Best Regards,

    Sujith

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 20, 2013 at 04:43 AM

    Hi Shine,

    Good to hear that your issue got resolved.

    Could you please share the code of entire webservice call including GET and POST method.

    Regards

    Sheetal

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 02, 2014 at 06:26 AM

    Hi All,

    i am develoing a native iOS application where I am trying to consume Odata services through Sybase Mobile Platform 2.3 and Relay server.

    I have tested my Odata service url in rest client also and its working fine.

    In my iOS code I am able to fetch the application end point but while fetching the service document I am getting this error SUPJsonException:expected string, found 173/Location:-[ODPRequest startSynchronous].

    My code is

    NSString *urlStr = [ODPAppSettings getApplicationEndpointWithError:&error];

    NSURL *urlNew = [NSURL URLWithString:urlStr];

    [SDMRequestBuilder enableXCSRF:YES];

    id<SDMRequesting> request = [SDMRequestBuilder requestWithURL:urlNew];

    [request setRequestMethod:@"GET"];

    [request setUsername:@"xxxxxx"];

    [request setPassword:@"xxxxxx"];

    [request addRequestHeader:@"Content-Type" value:@"application/atom+xml;type=entry"];

    [request addRequestHeader:@"X-Requested-With" value:@"XMLHttpRequest"];

    [request startSynchronous];


    My netweaver server version is 7.4. Could anyone please help me to resolve this issue.



    With Regards

    Neha Pandey

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 18, 2014 at 12:13 PM

    Hi Shine Gopal,

    I'm also have same problem. System.Net.WebException: The remote server returned an error: (403) Forbidden. Could you please send your post request code so that I can refer.

    And I didn't get about formatting cookie can you please elaborate because am new to this.

    With Regards

    Durai Venkatesh

    Add comment
    10|10000 characters needed characters exceeded