Web API is not working when calling through C# or jQuery ajax?Ask Questions

 Posted on 08/08/2018 4:30:26 PM

This case is driving me nuts. The first call sets the session and the 2nd call gets the session. First 'Post' call return username and session id correctly but when I try to get the session, it returns blank with status code 200.

The same is the case with HttpClient (C#) code.

Both the call works perfectly if I try to set through browser or PostMan.

        $.ajax({
        url: "http://localhost:xxxx/xxxx/api/v1/session?username=xxxx&password=xxxx", 
        type: 'POST',            
        dataType: 'application/json',
        success: function (result) {
            $.ajax({
                url: "http://localhost:xxxx/xxxx/api/v1/session",
                type: 'Get',
                dataType: 'application/json',
                crossDomain: true,
                success: function (result) {
                    debugger;

                },
                error: function (result) {
                    debugger;
                }
            });
        },
        error: function (result) {
            debugger;
            $.ajax({
                url: "http://localhost:xxxx/xxxx/api/v1/session",
                type: 'Get',
                dataType: 'application/json',
                crossDomain: true,

                success: function (result) {
                    debugger

                },
                error: function (result) {
                    debugger;
                }
            });
        }
    });

The Get Request from Post Man {"sessionId":"088BE3296B8778948F649A6B7B8C064B","userName":"user1"}

Am I missing anything?

Do note that Web-APIs are exposed by third party.

Share On: facebook gplus twitter
profile
Asked by Hardik Bera on 08/08/2018 4:30:26 PM Score: 375 points
Add Comment:
Submit

Comments

1 Answer

0 Corrected Answers
2
Profile
Answered by Shailesh Chaudhary on Oct 8 2018 9:03AM Score: 681 points

Hello Hardik this may help you.

Usually, in the response for the POST request, there will be a Set-Cookie header.

You may need to pass the cookie in the GET request.

Add Comment:

Post Your Answer

  •  
  •  

Existing Members

Sign in to your account
Email Address
Password
...or Join us
Download, Vote, Comment, Publish.
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.